Friday, April 1, 2011

Log handlers or appenders in Java APIs

Each logger can have access to several handler.
The handler receives the log message from the logger and exports it to a certain target
A handler can be turn off with setLevel(Level.OFF) and turned on with setLevel(...)
You have several standard handler, e.g.

  • ConsoleHandler: Write the log message to console
  • FileHandler: Writes the log message to file
Log Levels INFO and higher will be automatically written to the console.
Handler[] handlers = Logger.getLogger( "" ).getHandlers();

//Now you can set individual handler level like this: 
handlers[index].setLevel( Level.FINE );

See log formatter.

No comments:

Post a Comment