19 package org.sleuthkit.autopsy.apputils;
21 import java.io.IOException;
22 import java.nio.file.Path;
23 import java.nio.file.Paths;
24 import java.sql.Timestamp;
25 import java.util.HashMap;
27 import java.util.logging.FileHandler;
28 import java.util.logging.Formatter;
29 import java.util.logging.LogRecord;
30 import java.util.logging.Logger;
47 private static final String
NEWLINE = System.lineSeparator();
48 private static final Map<String, Logger>
loggers =
new HashMap<>();
59 if (loggers.containsKey(logName)) {
60 logger = loggers.get(logName);
67 fileHandler.setFormatter(
new Formatter() {
69 public String format(LogRecord record) {
70 Throwable thrown = record.getThrown();
71 String stackTrace =
"";
72 while (thrown != null) {
73 stackTrace += thrown.toString() +
NEWLINE;
74 for (StackTraceElement traceElem : record.getThrown().getStackTrace()) {
75 stackTrace +=
"\t" + traceElem.toString() +
NEWLINE;
77 thrown = thrown.getCause();
79 return (
new Timestamp(record.getMillis())).toString() +
" "
80 + record.getSourceClassName() +
" "
81 + record.getSourceMethodName() + NEWLINE
82 + record.getLevel() +
": "
83 + this.formatMessage(record) + NEWLINE
87 logger.addHandler(fileHandler);
88 logger.setUseParentHandlers(
false);
89 }
catch (SecurityException | IOException ex) {
90 throw new RuntimeException(String.format(
"Error initializing file handler for %s", logFilePath), ex);
92 loggers.put(logName, logger);
static final int LOG_SIZE
static final String NEWLINE
synchronized static Logger getLogger(String logName)
static final int LOG_FILE_COUNT
static final Map< String, Logger > loggers
synchronized static Logger getLogger(String name)