0

I want to use log4j to log different content to different files. Therefore i created the following config file (at the moment everything gets written to the console aswell):

log4j.rootLogger=TRACE, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n log4j.appender.debugLog=org.apache.log4j.FileAppender log4j.appender.debugLog.File=logs/debug.log log4j.appender.debugLog.layout=org.apache.log4j.PatternLayout log4j.appender.debugLog.layout.ConversionPattern=%d [%24F:%t:%L] - %m%n log4j.appender.reportsLog=org.apache.log4j.FileAppender log4j.appender.reportsLog.File=logs/reports.log log4j.appender.reportsLog.layout=org.apache.log4j.PatternLayout log4j.appender.reportsLog.layout.ConversionPattern=%m%n log4j.category.reportsLogger=DEBUG, reportsLog log4j.additivity.reportsLogger=false log4j.category.debugLogger=DEBUG, debugLog log4j.additivity.debugLogger=false 

and I use the loggers a follows:

public class Main { private static final Logger debugLog = Logger.getLogger("debugLog"); private static final Logger perfLog = Logger.getLogger("reportsLog"); public static void main(String argv[]) { debugLog.debug("Starting"); perfLog.debug("Starting"); } } 

The problem: The log files get created but are empty. only the output at the console gets displayed. Do I have my config file wrong?

4
  • Duplicate of stackoverflow.com/questions/29882310/log4j-empty-log-file Commented Oct 20, 2015 at 18:22
  • with this answer everything gets logged everywhere. Commented Oct 20, 2015 at 18:25
  • 2
    Your category is called debugLogger, but you are creating the logger with debugLog (same for reports). Commented Oct 20, 2015 at 18:37
  • Ah stupid ... If you want you can post it and im going to accept it... Commented Oct 20, 2015 at 19:06

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.