apache logger 使用
apache common logging也是一个比较有名的log包。其实它只是简单封装了一些现有的log框架。1. 只是一个框架
2. 如果有 commons-logging.properties 配置文件, 可以用它来配置使用哪个框架,以及各个框架的优先级
3. 如果没有上述文件,会搜索系统中现在的日志框架,优先是log4j, 然后是 jdk 的logger
4. 如果连jdk logger都没有,可以使用自带的 simplelog, 将所有的Log实例的日志输出到 System.out中
java -D org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog ...
如果使用jdk的logger,可以建logging.properties文件,在里面进行配置,例子如下:
# handlers
handlers=java.util.logging.FileHandler, java.util.logging.ConsoleHandler
# general level
# 7个级别,从高到低分别为:SEVERE,WARNING,INFO,CONFIG,FINE,FINER,FINEST 还可以为ALL和OFF
.level=INFO,比设置低的将不输出
# file handler
java.util.logging.FileHandler.pattern = %h/java%u.log
java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter
java.util.logging.FileHandler.append = true
# console handler
java.util.logging.ConsoleHandler.level = FINEST
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
test.de.jayefem.log4e.logkits.JDK1_4_Logging.level = FINEST
可以参考 jre/lib 下的同名文件。
代码里:
static Log log = LogFactory.getLog(this.class); //作为类的静态成员
log.info("...");
log.debug("");
一般来说,要用debug,应将level设为 fine 以下。
附:
[*]java.util.logging.FileHandler.level specifies the default level for the Handler (defaults to Level.ALL).
[*]java.util.logging.FileHandler.filter specifies the name of a Filter class to use (defaults to no Filter).
[*]java.util.logging.FileHandler.formatter specifies the name of a Formatter class to use (defaults to java.util.logging.XMLFormatter)
[*]java.util.logging.FileHandler.encoding the name of the character set encoding to use (defaults to the default platform encoding).
[*]java.util.logging.FileHandler.limit specifies an approximate maximum amount to write (in bytes) to any one file. If this is zero, then there is no limit. (Defaults to no limit).
[*]java.util.logging.FileHandler.count specifies how many output files to cycle through (defaults to 1).
[*]java.util.logging.FileHandler.pattern specifies a pattern for generating the output file name. See below for details. (Defaults to "%h/java%u.log").
[*]java.util.logging.FileHandler.append specifies whether the FileHandler should append onto any existing files (defaults to false).
A pattern consists of a string that includes the following special components that will be replaced at runtime:
[*]"/" the local pathname separator
[*]"%t" the system temporary directory
[*]"%h" the value of the "user.home" system property
[*]"%g" the generation number to distinguish rotated logs
[*]"%u" a unique number to resolve conflicts
[*]"%%" translates to a single percent sign "%"
参与:http://blog.csdn.net/llmlx/archive/2008/11/25/3370144.aspx
页:
[1]