Friday, April 1, 2011

Formatting or rendering via logging

Each handlers output can be configured with a formatter
Available formatter
  • SimpleFormatter Generate all messages as text
  • XMLFormatter Generates XML output for the log messages 
Log entries can be sent to these destinations, as either simple text or as XML :
  • the console
  • a file
  • a stream
  • memory
  • a TCP socket on a remote host
class MyHtmlFormatter extends Formatter{

//this method is called for every log records
public String format(LogRecord record)
StringBuffer buf = new StringBuffer(1000);
//if level is greater than warning, bold the content
if (record.getLevel().intValue() >= Level.WARNING.intValue()){
//else do something else
//and so on
return buf.toString();

No comments:

Post a Comment