// : c15:CustomHandler.java
//How to write custom handler
//From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
//www.BruceEckel.com. See copyright notice in CopyRight.txt.
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
public class CustomHandler {
private static Logger logger = Logger.getLogger("CustomHandler");
private static List strHolder = new ArrayList();
public static void main(String[] args) {
logger.addHandler(new Handler() {
public void publish(LogRecord logRecord) {
strHolder.add(logRecord.getLevel() + ":");
strHolder.add(logRecord.getSourceClassName() + ":");
strHolder.add(logRecord.getSourceMethodName() + ":");
strHolder.add("<" + logRecord.getMessage() + ">");
strHolder.add("\n");
}
public void flush() {
}
public void close() {
}
});
logger.warning("Logging Warning");
logger.info("Logging Info");
System.out.print(strHolder);
}
} ///:~
|