Types of Logging
Log4j and logging services
Configuring logging
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:
TRACE
DEBUG
INFO
WARN
ERROR
FATAL
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.
TRACE<DEBUG
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 - A 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).
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, at most, 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.
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.