-Dnet.filebot.logger.cli.anonymize

This commit is contained in:
Reinhard Pointner 2016-02-09 16:44:49 +00:00
parent fcb003f440
commit aba1effc83
1 changed files with 21 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.regex.Pattern;
import org.codehaus.groovy.runtime.StackTraceUtils;
@ -27,10 +28,28 @@ class CLILogging extends Handler {
return log;
}
private static final Pattern ANONYMIZE_PATTERN = getAnonymizePattern();
private static Pattern getAnonymizePattern() {
String pattern = System.getProperty("net.filebot.logger.cli.anonymize");
if (pattern != null && pattern.length() > 0) {
return Pattern.compile(pattern, Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CHARACTER_CLASS);
}
return null;
}
public String getMessage(LogRecord record) {
if (ANONYMIZE_PATTERN != null) {
return ANONYMIZE_PATTERN.matcher(record.getMessage()).replaceAll("");
}
return record.getMessage();
}
@Override
public void publish(LogRecord record) {
if (record.getLevel().intValue() <= getLevel().intValue())
if (record.getLevel().intValue() <= getLevel().intValue()) {
return;
}
// make sure all previous messages are already flushed
System.out.flush();
@ -40,7 +59,7 @@ class CLILogging extends Handler {
PrintStream out = record.getLevel().intValue() < Level.WARNING.intValue() ? System.out : System.err;
// print messages
out.println(record.getMessage());
out.println(getMessage(record));
if (record.getThrown() != null) {
StackTraceUtils.deepSanitize(record.getThrown()).printStackTrace(out);
}