本文介绍了使用Log4j的多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用log4j记录一些信息.我想将这些信息分成多个文件.
I'm using log4j to log several informations. I'd like to separate these infos into multiple files.
我的配置文件与此类似:
My configuration file is similar to this:
#logger_1
log4j.logger.logger_1=debug, logger_1_File
log4j.appender.logger_1_File=org.apache.log4j.RollingFileAppender
log4j.appender.logger_1_File.layout=org.apache.log4j.PatternLayout
log4j.appender.logger_1_File.layout.ConversionPattern=%d{ABSOLUTE} %m%n
log4j.appender.logger_1_File.File=${webinf}/logs/logger1/logger1.log
log4j.appender.logger_1_File.MaxFileSize=5000KB
log4j.appender.logger_1_File.MaxBackupIndex=200
log4j.appender.logger_1_File.encoding=UTF-8
#logger_2
log4j.logger.logger_2=debug, logger_2_File
log4j.appender.logger_2_File=org.apache.log4j.RollingFileAppender
log4j.appender.logger_2_File.layout=org.apache.log4j.PatternLayout
log4j.appender.logger_2_File.layout.ConversionPattern=%d{ABSOLUTE} %m%n
log4j.appender.logger_2_File.File=${webinf}/logs/logger2/logger2.log
log4j.appender.logger_2_File.MaxFileSize=5000KB
log4j.appender.logger_2_File.MaxBackupIndex=200
log4j.appender.logger_2_File.encoding=UTF-8
...
对此我有两个问题:
- 有什么我可以缩写的方法吗?这个(省略重复/样板代码)?我必须重复很多当我使用几个appenders行.
- 是 有任何性能问题 它?此配置意味着log4j保持 要写入的几种资源 文件.可以 造成性能问题?一世 有9个像这样的Appender,所以我 对此感到担心.
- Is there any way I could abbreviatethis (omit the repeated/boilerplatecode)? I have to repeat a lot ofline when I use several appenders.
- Is there any performance problem with it? This config means log4j holds several resources to write into files. Does it cause performance problems? I have 9 appenders like these so I'm worried about it.
推荐答案
首先,使用一个附加程序,多个附加程序和不同的日志级别来衡量应用程序的性能. 如果遇到性能问题,则需要解决它,否则就不必担心.
First of all, measure the performance of your app with a single appender, with many appenders, with different log levels. If you have a performance issue, you need to solve it, otherwise no need to worry about it.
Also read the "Performance" section at the end of the Short introduction to log4j.
这篇关于使用Log4j的多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!