首页 > 代码库 > Configuring log4j
Configuring log4j
Configuring log4j typically involes assigning level objects, defining appender objects, and specifying Layout objects.
- naming and placing the configuation file
By default, the LogManager class will look for a file named log4j.properties or log4j.xml in the classpath used for loading the log4j classes.
If you decide to name your configuation file differently, you are free to do that. However you have to let the log4j framework know by supplying a command line argument as follows:
-Dlog4j.cofinguation="file_name".
# define the root logger with two appenders writing to console and filelog4j.rootLogger = DEBUG, CONSOLE, FILE#define your own logger named com.foo#and assign level and appender to your own loggerlog4j.logger.com.foo=DEBUG,FILE#define the appender named FILElog4j.appender.FILE=org.apache.log4j.FileAppenderlog4j.appender.FILE.File=${user.home}/log.out#define the appender named CONSOLElog4j.appender.CONSOLE=org.apache.log4j.ConsoleAppenderlog4j.appender.CONSOLE.conversionPattern=%m%n
notable points about Configuration
- the configuation file is case-sensive
- a few of appenders can be only configured through an XMl file
- some advanced controls, such as Filter and ObjectRender, can be configured only via an XML file.
Configuring log4j
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。