Log4J相关杂抄
杂抄地址:http://logging.apache.org/log4j/1.2/manual.htmlLog4j has three main components: loggers, appenders and layouts.
These three types of components work together to enable developers to log messages according to message type and level, and to control at runtime how these messages are formatted and where they are reported.
The ability to selectively enable or disable logging requests based on their logger is only part of the picture. Log4j allows logging requests to print to multiple destinations. In log4j speak, an output destination is called an appender. Currently, appenders exist for the console, files, GUI components, remote socket servers, JMS, NT Event Loggers, and remote UNIX Syslog daemons. It is also possible to log asynchronously.
// get a logger instance named "com.foo" Loggerlogger = Logger.getLogger("com.foo");// Now set its level. Normally you do not need to set the// level of a logger programmatically. This is usually done// in configuration files. logger.setLevel(Level.INFO); Logger barlogger = Logger.getLogger("com.foo.Bar");// This request is enabled, because WARN >= INFO. logger.warn("Low fuel level.");// This request is disabled, because DEBUG < INFO. logger.debug("Starting search for nearest gas station.");// The logger instance barlogger, named "com.foo.Bar",// will inherit its level from the logger named// "com.foo" Thus, the following request is enabled// because INFO >= INFO. barlogger.info("Located nearest gas station.");// This request is disabled, because DEBUG < INFO. barlogger.debug("Exiting gas station search");
The output of a log statement of logger C will go to all the appenders in C and its ancestors. This is the meaning of the term "appender additivity".
However, if an ancestor of logger C, say P, has the additivity flag set to false, then C's output will be directed to all the appenders in C and it's ancestors upto and including P but not the appenders in any of the ancestors of P.
Loggers have their additivity flag set to true by default.
log4j.rootLogger=debug, stdout, Rlog4j.appender.stdout=org.apache.log4j.ConsoleAppenderlog4j.appender.stdout.layout=org.apache.log4j.PatternLayout# Pattern to output the caller's file name and line number.log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%nlog4j.appender.R=org.apache.log4j.RollingFileAppenderlog4j.appender.R.File=example.loglog4j.appender.R.MaxFileSize=100KB# Keep one backup filelog4j.appender.R.MaxBackupIndex=1log4j.appender.R.layout=org.apache.log4j.PatternLayoutlog4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
页:
[1]