tags:

views:

691

answers:

2

I don't seem to be getting any INFO level messages into Additions.log or Deletions.log even though I see the logging line get 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 is getting my loggers from the class:

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

What else do I need to troubleshoot to figure this out?

+1  A: 

Comparing this to my own log4j multi-file-writing configuration I'd recommend:

  1. Move your log4j.logger and log4j.additivity lines so they are after the log4j.appender statements.
  2. Modify log4j.logger to specify the appender, as in "log4j.logger.Additions=INFO, Additions"

It becomes a little clearer when your appender has a different name from the logger. 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
AKeller
+4  A: 

You're confusing Loggers with Appenders. You've defined Loggers called Additions and Deletions, and you've defined Appenders with the same names, but you need to associate the two. Simply giving them the same name is not enough.

I suggest that you rename the appenders to be distinct from the Loggers, to avoid this confusion. You then need to assign appenders to the Loggers like this:

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

Lastly, I suggest that you consider moving from the properties format to the XML format. It's an awful lot more readable, in my opinion, and it's obvious what everything else and what the structures are.

skaffman