使用Log4j的多个文件 [英] Multiple files with Log4j

查看:100
本文介绍了使用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

...

对此我有两个问题:

  1. 有什么我可以缩写的方法吗? 这个(省略重复/样板 代码)?我必须重复很多 当我使用几个appenders行.
  2. 是 有任何性能问题 它?此配置意味着log4j保持 要写入的几种资源 文件.可以 造成性能问题?一世 有9个像这样的Appender,所以我 对此感到担心.
  1. Is there any way I could abbreviate this (omit the repeated/boilerplate code)? I have to repeat a lot of line when I use several appenders.
  2. 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.

还请阅读 log4j的简短介绍末尾的性能"部分. /a>.

Also read the "Performance" section at the end of the Short introduction to log4j.

这篇关于使用Log4j的多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆