Merge pull request #1579 from millmanorama/use_logger_instead_of_printing_stacktrace

replace Exception.printStackTrace with proper logging
This commit is contained in:
Richard Cordovano 2015-09-17 17:22:44 -04:00
commit 3c55f259d9
3 changed files with 68 additions and 24 deletions

View File

@ -1,7 +1,7 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2013 Basis Technology Corp.
* Copyright 2013-15 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
@ -21,10 +21,12 @@ package org.sleuthkit.autopsy.timeline;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import org.apache.commons.lang3.StringUtils;
import org.openide.util.Exceptions;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.coreutils.ThreadConfined;
/**
* This class supports programmer productivity by abstracting frequently used
@ -34,32 +36,53 @@ import org.openide.util.Exceptions;
* at
* http://stackoverflow.com/questions/11734885/javafx2-very-poor-performance-when-adding-custom-made-fxmlpanels-to-gridpane.
*
* NOTE: As described in the link above above, using FXMLConstructor will be
* inefficient if FXML is used as a template for many similar items. In that use
* case, it is much faster to build the entire hierarchy in Java. This class is
* intended only to remove the boilerplate initialization code when defining a
* relatively static layout
*
* TODO: find a way to move this to CoreUtils and remove duplicate verison in
* image analyzer
*/
public class FXMLConstructor {
static public void construct(Node n, String fxmlFileName) {
final String name = "nbres:/" + StringUtils.replace(n.getClass().getPackage().getName(), ".", "/") + "/" + fxmlFileName; // NON-NLS
System.out.println(name);
private static final Logger LOGGER = Logger.getLogger(FXMLConstructor.class.getName());
/**
* Load an fxml file and initialize a node with it. Since this manipulates
* the node, it must be called on the JFX thread.
*
*
* @param node a node to initialize from a loaded FXML
* @param fxmlFileName the the file name of the FXML to load, relative to
* the package that the class of node is defined in.
*/
@ThreadConfined(type = ThreadConfined.ThreadType.JFX)
static public void construct(Node node, String fxmlFileName) {
final String name = "nbres:/" + StringUtils.replace(node.getClass().getPackage().getName(), ".", "/") + "/" + fxmlFileName; // NON-NLS
try {
FXMLLoader fxmlLoader = new FXMLLoader(new URL(name));
fxmlLoader.setRoot(n);
fxmlLoader.setController(n);
fxmlLoader.setRoot(node);
fxmlLoader.setController(node);
try {
fxmlLoader.load();
} catch (IOException exception) {
LOGGER.log(Level.SEVERE, "FXMLConstructor was unable to load FXML, falling back on default Class Loader, and trying again.", exception);
try {
fxmlLoader.setClassLoader(FXMLLoader.getDefaultClassLoader());
fxmlLoader.load();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
LOGGER.log(Level.SEVERE, "FXMLConstructor was unable to load FXML, node initialization may not be complete.", ex);
}
}
} catch (MalformedURLException ex) {
Exceptions.printStackTrace(ex);
LOGGER.log(Level.SEVERE, "FXMLConstructor was unable to load FXML, node initialization may not be complete.", ex);
}
}
private FXMLConstructor() {
}
}

View File

@ -23,10 +23,11 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.logging.Level;
import javafx.scene.image.Image;
import org.apache.commons.lang3.StringUtils;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.timeline.zooming.EventTypeZoomLevel;
import org.sleuthkit.datamodel.AbstractFile;
import org.sleuthkit.datamodel.BlackboardArtifact;
@ -57,7 +58,7 @@ public enum MiscTypes implements EventType, ArtifactEventType {
BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME,
new AttributeExtractor(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PROG_NAME),
new AttributeExtractor(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_LOCATION),
(BlackboardArtifact artf, Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> attrMap) -> {
(artf, attrMap) -> {
final BlackboardAttribute latStart = attrMap.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE_START);
final BlackboardAttribute longStart = attrMap.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LONGITUDE_START);
final BlackboardAttribute latEnd = attrMap.get(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_GEO_LATITUDE_END);
@ -129,18 +130,16 @@ public enum MiscTypes implements EventType, ArtifactEventType {
BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_CREATED,
new AttributeExtractor(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DEVICE_MAKE),
new AttributeExtractor(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DEVICE_MODEL),
(BlackboardArtifact t,
Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute> u) -> {
(artifact, attributeMap) -> {
try {
AbstractFile f = t.getSleuthkitCase().getAbstractFileById(t.getObjectID());
if (f != null) {
return f.getName();
AbstractFile file = artifact.getSleuthkitCase().getAbstractFileById(artifact.getObjectID());
if (file != null) {
return file.getName();
}
return " error loading file name"; // NON-NLS
} catch (TskCoreException ex) {
Exceptions.printStackTrace(ex);
return " error loading file name"; // NON-NLS
Logger.getLogger(MiscTypes.class.getName()).log(Level.SEVERE, "Exif event type failed to look up backing file name", ex);
}
return " error loading file name"; // NON-NLS
}),
DEVICES_ATTACHED(NbBundle.getMessage(MiscTypes.class, "MiscTypes.devicesAttached.name"), "usb_devices.png", // NON-NLS
BlackboardArtifact.ARTIFACT_TYPE.TSK_DEVICE_ATTACHED,
@ -185,26 +184,41 @@ public enum MiscTypes implements EventType, ArtifactEventType {
private final BiFunction<BlackboardArtifact, Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute>, String> shortExtractor;
/**
* {@inheritDoc }
*/
@Override
public BiFunction<BlackboardArtifact, Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute>, String> getFullExtractor() {
return longExtractor;
}
/**
* {@inheritDoc }
*/
@Override
public BiFunction<BlackboardArtifact, Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute>, String> getMedExtractor() {
return medExtractor;
}
/**
* {@inheritDoc }
*/
@Override
public BiFunction<BlackboardArtifact, Map<BlackboardAttribute.ATTRIBUTE_TYPE, BlackboardAttribute>, String> getShortExtractor() {
return shortExtractor;
}
/**
* {@inheritDoc }
*/
@Override
public BlackboardAttribute.ATTRIBUTE_TYPE getDateTimeAttrubuteType() {
return dateTimeAttributeType;
}
/**
* {@inheritDoc }
*/
@Override
public EventTypeZoomLevel getZoomLevel() {
return EventTypeZoomLevel.SUB_TYPE;

View File

@ -22,6 +22,7 @@ import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import javafx.beans.Observable;
import javax.swing.Action;
import org.joda.time.DateTime;
@ -29,8 +30,8 @@ import org.joda.time.DateTimeZone;
import org.openide.nodes.Children;
import org.openide.nodes.PropertySupport;
import org.openide.nodes.Sheet;
import org.openide.util.Exceptions;
import org.openide.util.lookup.Lookups;
import org.sleuthkit.autopsy.coreutils.Logger;
import org.sleuthkit.autopsy.datamodel.DataModelActionsFactory;
import org.sleuthkit.autopsy.datamodel.DisplayableItemNode;
import org.sleuthkit.autopsy.datamodel.DisplayableItemNodeVisitor;
@ -46,6 +47,8 @@ import org.sleuthkit.datamodel.Content;
*/
class EventNode extends DisplayableItemNode {
private static final Logger LOGGER = Logger.getLogger(EventNode.class.getName());
private final TimeLineEvent e;
EventNode(TimeLineEvent eventById, AbstractFile file, BlackboardArtifact artifact) {
@ -75,7 +78,7 @@ class EventNode extends DisplayableItemNode {
try {
timePropery.setValue(getDateTimeString());
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
Exceptions.printStackTrace(ex);
LOGGER.log(Level.SEVERE, "unexpected error setting date/time property on EventNode explorer node", ex);
}
});
@ -105,7 +108,7 @@ class EventNode extends DisplayableItemNode {
final List<Action> factoryActions = DataModelActionsFactory.getActions(content, artifact != null);
actionsList.addAll(factoryActions);
return actionsList.toArray(new Action[0]);
return actionsList.toArray(new Action[actionsList.size()]);
}
@Override
@ -118,7 +121,11 @@ class EventNode extends DisplayableItemNode {
throw new UnsupportedOperationException("Not supported yet."); // NON-NLS //To change body of generated methods, choose Tools | Templates.
}
class TimeProperty extends PropertySupport.ReadWrite<String> {
/**
* We use TimeProperty instead of a normal NodeProperty to correctly display
* the date/time when the user changes the timezone setting.
*/
private class TimeProperty extends PropertySupport.ReadWrite<String> {
private String value;
@ -127,7 +134,7 @@ class EventNode extends DisplayableItemNode {
return false;
}
public TimeProperty(String name, String displayName, String shortDescription, String value) {
TimeProperty(String name, String displayName, String shortDescription, String value) {
super(name, String.class, displayName, shortDescription);
setValue("suppressCustomEditor", Boolean.TRUE); // remove the "..." (editing) button NON-NLS
this.value = value;