六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 67|回复: 0

Log4J相关杂抄

[复制链接]

升级  72%

8

主题

8

主题

8

主题

童生

Rank: 1

积分
36
 楼主| 发表于 2013-1-27 04:48:34 | 显示全部楼层 |阅读模式
杂抄地址:http://logging.apache.org/log4j/1.2/manual.html
 
    Log4j 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"   Logger  logger = 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 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表