Configuring the Log Format


If you look carefully at the server.log file and compare it to the messages output to the console, you'll notice that the formats are quite different. The log messages in server.log have a more precise time and show the fully qualified category name that the message is logged under. Each appender can declare the messages logged to it. We'll look at how to do that now.

How do I do that?

Each appender declares a layout to be used to output the log message using a layout element. Here is the normal configuration for the console log again:

     <appender name="CONSOLE" >         <errorHandler />         <param name="Target" value="System.out"/>         <param name="Threshold" value="INFO"/>         <layout >             <!-- The default pattern: Date Priority [Category] Message\n -->             <param name="ConversionPattern"                    value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>         </layout>     </appender> 

The ConversionPattern parameter controls the log format. We won't go into all the pattern options here. You can find full documentation of formatting options at http://logging.apache.org/log4j/docs/api/org/apache/log4j/PatternLayout.html.

Let's suppose you want to log the name of the thread that generated the log message. The pattern layout option for the thread name is %t. You just need to add that to ConversionPattern to make the change:

     <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] (%t) %m%n"/> 

After the change takes effect, the console log should begin logging messages like this:

     00:26:37,856 INFO  [TaskBean] (http-0.0.0.0-8080-2:) Created:     local/Task@1735136:34df95cec0a8006500811ae4bccfc6e2 



JBoss. A Developer's Notebook
JBoss: A Developers Notebook
ISBN: 0596100078
EAN: 2147483647
Year: 2003
Pages: 106

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net