2010-10-28 3 views
1

J'utilise Log4j dans mon application, et les bibliothèques que j'utilise et qui utilisent également Log4j publient également leurs journaux dans les fichiers journaux que je crée. J'ai déjà créé des appenders pour rediriger les journaux d'une bibliothèque vers un fichier "other.log", mais les autres bibliothèques continuent de se connecter à mon fichier "info.log" principal.Log4j - Exclure la journalisation de certaines classes

Ceci est mes propriétés log4j.properties. Notez qu'à la fin, je crée une catégorie pour la bibliothèque alibrary.apackage et une catégorie pour myproject.apackage, de sorte que les journaux de bibliothèque vont à un appender et les journaux de projet vont à un autre appender.

log4j.rootLogger=ALL,InfoAppender,OtherAppender 

# AdminFileAppender - used to log messages in the admin.log file. 
log4j.appender.InfoAppender=org.apache.log4j.FileAppender 
log4j.appender.InfoAppender.File=info.log 
log4j.appender.InfoAppender.layout=org.apache.log4j.PatternLayout 
log4j.appender.InfoAppender.layout.ConversionPattern= %d{yyyy/MM/dd HH:mm:ss,SSS} [%t] %-5p %c %x - %m%n 
log4j.appender.InfoAppender.Threshold=DEBUG 

log4j.appender.OtherAppender=org.apache.log4j.FileAppender 
log4j.appender.OtherAppender.File=other.log 
log4j.appender.OtherAppender.layout=org.apache.log4j.PatternLayout 
log4j.appender.OtherAppender.layout.ConversionPattern= %d{yyyy/MM/dd HH:mm:ss,SSS} [%t] %-5p %c %x - %m%n 
log4j.appender.OtherAppender.Threshold=ALL 

log4j.category.alibrary.apackage=DEBUG,OtherAppender 
log4j.additivity.com.mchange.v2=false 
log4j.category.myproject.apackage=ALL,InfoAppender 
log4j.additivity.trackme=false 

Je garde toujours obtenir ce qui suit si:

Dans le "info.log":

...Logs that I want to be here... 
Logs that I do not want to be here, that should go to "other.log". Ex.: 
2010/10/28 15:29:25,667 [main] DEBUG org.apache.jasper.compiler.JspRuntimeContext - Parent class loader is: [email protected] 
2010/10/28 15:29:25,668 [main] DEBUG org.apache.jasper.servlet.JspServlet - ... 
2010/10/28 15:29:25,668 [main] DEBUG org.apache.jasper.servlet.JspServlet - IMPORTANT: Do not modify the generated servlets 

Dans le "other.log":

All the logs that I do not want in "info.log" are here. OK. 

Mon question est: Comment puis-je rediriger tous les journaux indésirables - c'est-à-dire, les journaux provenant d'autres bibliothèques - pour le "other.log"?

Répondre

2

Vous voulez faire d'OtherAppender le rootLogger et pousser spécifiquement les messages que vous voulez dans InfoAppender.

Je laisse les définitions appender même, puis configurer les enregistreurs comme ceci:

log4j.rootLogger=ALL,OtherAppender 
log4j.category.alibrary.apackage=DEBUG # will default to OtherAppender 
log4j.additivity.com.mchange.v2=false 
log4j.category.myproject.apackage=ALL,InfoAppender # will go to both logs 
log4j.additivity.trackme=false 

qui acheminera tout en OtherAppender et juste des choses de myproject.apackage dans InfoAppender.

Questions connexes