-Dnet.filebot.logger.cli.anonymize
This commit is contained in:
parent
fcb003f440
commit
aba1effc83
|
@ -7,6 +7,7 @@ import java.util.logging.Handler;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.LogRecord;
|
import java.util.logging.LogRecord;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.codehaus.groovy.runtime.StackTraceUtils;
|
import org.codehaus.groovy.runtime.StackTraceUtils;
|
||||||
|
|
||||||
|
@ -27,10 +28,28 @@ class CLILogging extends Handler {
|
||||||
return log;
|
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
|
@Override
|
||||||
public void publish(LogRecord record) {
|
public void publish(LogRecord record) {
|
||||||
if (record.getLevel().intValue() <= getLevel().intValue())
|
if (record.getLevel().intValue() <= getLevel().intValue()) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// make sure all previous messages are already flushed
|
// make sure all previous messages are already flushed
|
||||||
System.out.flush();
|
System.out.flush();
|
||||||
|
@ -40,7 +59,7 @@ class CLILogging extends Handler {
|
||||||
PrintStream out = record.getLevel().intValue() < Level.WARNING.intValue() ? System.out : System.err;
|
PrintStream out = record.getLevel().intValue() < Level.WARNING.intValue() ? System.out : System.err;
|
||||||
|
|
||||||
// print messages
|
// print messages
|
||||||
out.println(record.getMessage());
|
out.println(getMessage(record));
|
||||||
if (record.getThrown() != null) {
|
if (record.getThrown() != null) {
|
||||||
StackTraceUtils.deepSanitize(record.getThrown()).printStackTrace(out);
|
StackTraceUtils.deepSanitize(record.getThrown()).printStackTrace(out);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue