diff --git a/source/net/filebot/Logging.java b/source/net/filebot/Logging.java index f94d0196..4ba60dc4 100644 --- a/source/net/filebot/Logging.java +++ b/source/net/filebot/Logging.java @@ -16,7 +16,7 @@ import org.codehaus.groovy.runtime.StackTraceUtils; public final class Logging { - public static final Logger log = getConsoleLogger(CmdlineInterface.class, Level.ALL, new ConsoleFormatter()); + public static final Logger log = getConsoleLogger(CmdlineInterface.class, Level.ALL, new ConsoleFormatter(getAnonymizePattern())); public static final Logger debug = getConsoleLogger(Logging.class, Level.ALL, new SimpleFormatter()); public static Logger getConsoleLogger(Class cls, Level level, Formatter formatter) { @@ -31,6 +31,14 @@ public final class Logging { return () -> String.format(format, args); } + private static Pattern getAnonymizePattern() { + String pattern = System.getProperty("net.filebot.logging.anonymize"); + if (pattern != null && pattern.length() > 0) { + return Pattern.compile(pattern, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CHARACTER_CLASS | Pattern.MULTILINE); + } + return null; + } + public static class ConsoleHandler extends Handler { public ConsoleHandler(Level level, Formatter formatter) { @@ -70,24 +78,20 @@ public final class Logging { public static class ConsoleFormatter extends Formatter { + private final Pattern anonymize; + + public ConsoleFormatter(Pattern anonymize) { + this.anonymize = anonymize; + } + @Override public String format(LogRecord record) { - if (ANONYMIZE_PATTERN != null) { - return ANONYMIZE_PATTERN.matcher(record.getMessage()).replaceAll("") + System.lineSeparator(); + String message = record.getMessage(); + if (anonymize != null) { + message = anonymize.matcher(record.getMessage()).replaceAll(""); } - return record.getMessage() + System.lineSeparator(); + return message + System.lineSeparator(); } - - } - - private static final Pattern ANONYMIZE_PATTERN = getAnonymizePattern(); - - private static Pattern getAnonymizePattern() { - String pattern = System.getProperty("net.filebot.logging.anonymize"); - if (pattern != null && pattern.length() > 0) { - return Pattern.compile(pattern, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CHARACTER_CLASS | Pattern.MULTILINE); - } - return null; } }