Import Static Class: Log Log
Import Static Class: Log Log
htm
import org.apache.log4j.Logger;
static Logger log = Logger.getLogger(A_basics.class.getName());
log.debug("Hello this is an debug message");
This will compile fine but throw run time exception regarding appender.
Concept:
The Logger class does not allow us to instantiate a new Logger instance but it
provides two static methods for obtaining a Logger object:
public static Logger getRootLogger();
public static Logger getLogger(String name);
Here the first of the two methods returns the application instance's root
logger and does not have a name.
Any other named Logger object instance is obtained through the second method
by passing the name of the logger.
The name of the logger can be any string you can pass, usually class or
package name. It is mentioned below:
static Logger log = Logger.getLogger(log4jExample.class.getName());
Logging Levels
ALL All levels including custom levels.
DEBUG Designates fine-grained informational events that are most useful
to debug an application.
INFO Designates informational messages that highlight the progress of
the application at coarse-grained level.
TRACE Designates finer-grained informational events than the DEBUG.
WARN Designates potentially harmful situations.
ERROR Designates error events that might still allow the application to
continue running.
FATAL Designates very severe error events that will presumably lead the
application to abort.
OFF The highest possible rank and is intended to turn off logging.
ALL < DEBUG < INFO < WARN < ERROR < FATAL < OFF.
TODO
FileAppender Configuration:
JDBCAppender Configuration: