0

I have a snippset that I use like gazillion times in Linux that absolutely have no problem. But on windows it fails.

log4j: Using URL [file:/C:/Users/vbb/Documents/NetBeansProjects/MailNotification/./log4j.properties] for automatic log4j configuration.
log4j: Reading configuration from URL file:/C:/Users/vbb/Documents/NetBeansProjects/MailNotification/./log4j.properties
log4j: Could not find root logger information. Is this OK?
log4j: Finished configuring.
log4j:WARN No appenders could be found for logger (com.mycompany.mailnotification.Main).
log4j:WARN Please initialize the log4j system properly.

The code like this:

 System.setProperty("log4j.configuration", new File(".", File.separatorChar + "log4j.properties").toURL().toString());
        final  Logger logger = Logger.getLogger(Main.class);
        logger.debug("Program start!");

Here is the properties file which is placed everywhere from src\main\resources, src\test\resources... In linux, I just place it in project folder.

# 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=log4j-application.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
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
Tiana987642
  • 696
  • 2
  • 10
  • 28
  • Possible duplicate of [log4j:WARN No appenders could be found for logger in web.xml](https://stackoverflow.com/questions/1266139/log4jwarn-no-appenders-could-be-found-for-logger-in-web-xml) – Joe Nov 11 '17 at 03:25
  • Hi, I mentioned my `log4j.properties` already had `log4j.rootLogger=DEBUG, stdout, file` :( These snippets work fine in Linux not Windows :( – Tiana987642 Nov 11 '17 at 03:29
  • 1
    Hi, I changed to use xml config and it just works :( – Tiana987642 Nov 11 '17 at 05:18

0 Answers0