开发者

log4j filtering based on EAR

开发者 https://www.devze.com 2023-02-28 09:09 出处:网络
Our app is currently logging using Log4j at application level. There are a开发者_开发知识库t least 8 EAR files, which are deployed when the server runs. All 8 EAR\'s are logging into File1.log file. I

Our app is currently logging using Log4j at application level. There are a开发者_开发知识库t least 8 EAR files, which are deployed when the server runs. All 8 EAR's are logging into File1.log file. I want to separate 1 ear. For example, 7 EAR files should conitnue logging in File1.log file however, the 8th one say ABCD.EAR should log into ABCD.LOG file.


I believe i have figured it out. Though it was an easy solution but all the examples across the internet was based on .properties file and i was looking for .xml file configuration.

  1. First of all, I need an appender

    < appender name="ABCD" class="org.apache.log4j.RollingFileAppender"> < param name="File" value="./logs/ABCD.log" /> < param name="Append" value="true" /> < param name="MaxFileSize" value="100MB" /> < param name="MaxBackupIndex" value="10" /> < layout class="provision.services.logging.PSPatternLayout"> < param name="conversionPattern" value="%d %D %S %-5p {%P} %#: [%-17c{5} %T] %m%n" /> < /layout> < /appender>

  2. Then i need to tell the logger, what class heirarchy to log using this. The ABCD.ear has file herirarchy as project.abcd.*. So i added this line in log4j.xml

    < logger name="project.abcd"> < level value="INFO"/> < appender-ref ref="ABCD"/> < /logger>

I hope this would be helpful for someone else.

P.S: Whats wrong with XML Formating in edit box?? ... my xml wasn't visible before, then i had to add spaces and now its not "formatted" properly .. :s

0

精彩评论

暂无评论...
验证码 换一张
取 消