com.jidesoft.utils.LoggerUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jide-oss Show documentation
Show all versions of jide-oss Show documentation
JIDE Common Layer (Professional Swing Components)
package com.jidesoft.utils;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
/**
* LoggerUtils contains two methods to allow logger to print certain level of message to console. This is mainly used
* for debugging purpose.
*/
public class LoggerUtils {
public static Handler enableLogger(String loggerName, Level level) {
Logger log = Logger.getLogger(loggerName);
log.setLevel(level);
Handler handler = new Handler() {
@SuppressWarnings({"UseOfSystemOutOrSystemErr"})
@Override
public void publish(LogRecord record) {
System.err.print(record.getMessage());
Object[] params = record.getParameters();
if (params != null) {
if (params.length > 0)
System.err.print("= ");
for (int i = 0; i < params.length; i++) {
System.err.print(params[i]);
if (i < params.length - 1)
System.err.print(", ");
}
}
System.err.println();
}
@Override
public void flush() {
}
@Override
public void close() throws SecurityException {
}
};
log.addHandler(handler);
return handler;
}
public static void disableLogger(String loggerName, Handler handler) {
Logger log = Logger.getLogger(loggerName);
log.setLevel(null);
log.removeHandler(handler);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy