Log4j: one class; the same level; two output files

I don't seem to be getting INFO level messages in Additions.log or Deletions.log, although I can see the logging line being executed in the debugger. Here is my log4j.properties file:

log4j.file.home=.

log4j.rootLogger=INFO, dest1
log4j.rootCategory=INFO, dest1
log4j.logger.org.hibernate=ERROR

log4j.category.dest1=INFO
log4j.appender.dest1=org.apache.log4j.ConsoleAppender
log4j.appender.dest1.layout=org.apache.log4j.PatternLayout
log4j.appender.dest1.layout.ConversionPattern=%-22d{dd/MMM/yyyy HH:mm:ss} %-8p %c [%t] - %m (%l)%n

#Log items that are being added
log4j.logger.Additions=INFO
log4j.additivity.Additions=false
log4j.appender.Additions=org.apache.log4j.RollingFileAppender
log4j.appender.Additions.File=${log4j.file.home}/Additions.log
log4j.appender.Additions.MaxFileSize=10000KB
log4j.appender.Additions.MaxBackupIndex=10
log4j.appender.Additions.layout=org.apache.log4j.PatternLayout
log4j.appender.Additions.layout.ConversionPattern=%-22d{dd/MMM/yyyy HH:mm:ss} %-8p %c [%t] - %m (%l)%n

#Log items that are being removed
log4j.logger.Deletions=INFO
log4j.additivity.Deletions=false
log4j.appender.Deletions=org.apache.log4j.RollingFileAppender
log4j.appender.Deletions.File=${log4j.file.home}/Deletions.log
log4j.appender.Deletions.MaxFileSize=10000KB
log4j.appender.Deletions.MaxBackupIndex=10
log4j.appender.Deletions.layout=org.apache.log4j.PatternLayout
log4j.appender.Deletions.layout.ConversionPattern=%-22d{dd/MMM/yyyy HH:mm:ss} %-8p %c [%t] - %m (%l)%n 

      

and here you get my loggers from the class:

private static Logger addLog = Logger.getLogger("Additions");
private static Logger deleteLog = Logger.getLogger("Deletions");

      

What else do I need for troubleshooting to figure this out?

+2


source to share


2 answers


You are confusing Loggers with Appenders. You have defined Loggers called Additions and Removals and you have defined Appenders with the same names, but you need to link them. Just giving them the same name is not enough.

I suggest you rename the appendix to be different from Loggers to avoid this confusion. Then you need to assign a counter for the registrars as follows:



log4j.logger.Additions=INFO, Additions
log4j.logger.Deletions=INFO, Deletions

      

Finally, I suggest you move from property format to XML format. This is, in my opinion, an awful lot of readability, and it is obvious what the rest is and what structures.

+6


source


Comparing this to my own log4j recording configuration, I would recommend:

  • Move your log4j.logger and log4j.additive lines so they are after the log4j.appender statements.
  • Modify log4j.logger to point to the application as in "log4j.logger.Additions = INFO, Add-ons"


This becomes a little clearer when your appender has a different name from the registrar. Here's part of mine:

log4j.appender.ChatLogs=org.apache.log4j.DailyRollingFileAppender
log4j.appender.ChatLogs.layout=org.apache.log4j.PatternLayout
log4j.appender.ChatLogs.layout.ConversionPattern=%d{yyyy-MMM-dd HH:mm:ss:SSS}: %m%n
log4j.appender.ChatLogs.File=logs/chats.log
log4j.appender.ChatLogs.Threshold=INFO
log4j.appender.ChatLogs.Priority=INFO
log4j.appender.ChatLogs.DatePattern='.'yyyy-MM-dd

log4j.logger.chatfilter.ChatFilterPlugin=info, ChatLogs
log4j.additivity.chatfilter.ChatFilterPlugin=false

      

+1


source







All Articles