0

log4j was working fine yesterday, today I started my app and it logs nothing. I'll show you my properties file, maybe you can spot me something:

# Root logger option
log4j.rootLogger=DEBUG, stdout, file
# Redirect log messages to console
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

# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=/Users/user2/logs1.txt
log4j.appender.file.MaxFileSize=100MB
log4j.appender.file.MaxBackupIndex=20
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

I have this logs1.txt in the appropriate folder. Trying to log like:

final static Logger logger = Logger.getLogger(MyClass.class);
logger.info("log");

Thanks

Jhonny
  • 587
  • 1
  • 6
  • 17
  • Could you add a test class as well? Also try setting `log4j.appender.file.BufferedIO=false` and see if that makes any difference – vsnyc Nov 20 '15 at 22:11
  • I just use log.info in that class and the execution goes to that point 100%. – Jhonny Nov 20 '15 at 22:25
  • The statement may get executed but not output anything in the logs and be buffered in memory hence I wanted you to test with `BufferedIO=false`. Another thing you can try is using [SimpleLog](https://commons.apache.org/proper/commons-logging/apidocs/org/apache/commons/logging/impl/SimpleLog.html) for testing i.e. `final static Logger logger = new SimpleLog('MyClass');` – vsnyc Nov 20 '15 at 22:28
  • Tried them, but unfortunately none of them works – Jhonny Nov 20 '15 at 22:33
  • Did you move paths by any chance? You could try specifying `java -Dlog4j.configuration=` see [this answer](http://stackoverflow.com/questions/1140358/how-to-initialize-log4j-properly). If you want I can post a sample log4j logger class, but not sure how to help more without a test case – vsnyc Nov 20 '15 at 23:07

0 Answers0