Types of Logging
Log4j and logging services
Configure logging service
Data logging is the process of recording events, with an automated computer program
JBoss AS uses log4j, an open source logging framework
Log4j is a tool to help the programmer output log statements to a variety of output targets.
Loggers may be assigned levels. The set of possible levels, that is:
Features of log4j
log4j supports multiple output appenders per logger.
The format of the log output can be easily changed by extending the Layout class.
The target of the log output as well as the writing strategy can be altered by implementations of the Appender interface.
log4j is optimized for speed.
log4j is designed to handle Java Exceptions from the start.
Log4J Pattern Layout
The PatternLayout, part of the standard log4j distribution, lets the user specify the output format according to conversion patterns similar to the C language printf function.
For example, the PatternLayout with the conversion pattern
“%r [%t] %-5p %c – %m%n” will output something akin to:
176 [main] INFO org.foo.Bar – Located nearest gas station.
The first field is the number of milliseconds elapsed since the start of the program. The second field is the thread making the log request. The third field is the level of the log statement. The fourth field is the name of the logger associated with the log request. The text after the ‘-‘ is the message of the statement.
JBOSS – Logging service
The log4j configuration file is located at server/xxx/conf/jboss-log4j.xml
By default, JBoss produces output to both the console and a log file (log/server.log).
These core tutorials will help you to learn the fundamentals of JBOSS. For an in-depth understanding and practical experience, explore Online JBOSS Training.
By default, The logging threshold for the console is INFO, For server.log no threshold
By default, The server.log file is created new each time the server is launched, and grows until the server is stopped or until midnight Listing shows how you can change the Appender for the server.log file to create, atmost, 20 log files of 10 MB in size each.
JBOSS – Application specific log
As another example, let’s say you wanted to set the output from the container-managed persistence engine to DEBUG level and to redirect it to a separate file, cmp.log, in order to analyze the generated SQL commands. You would add the following code to the conf/jboss-log4j.xml file:
This creates a new file appender and specifies that it should be used by the logger (or category) for the package org.jboss.ejb.plugins.cmp.
The file appender is set up to produce a new log file every day rather than producing a new one every time you restart the server or writing to a single file indefinitely. The current log file is cmp.log. Older files have the date they were written added to their filenames.
For indepth understanding on JBoss click on: