2

I have a Java Application with this following log4j configuration properties, called log4j-DEV.properties:

################################################################ # Root logger option ############################################################### log4j.rootLogger=ALL, file,stdout ############################################################### ############################################################### # Logger response ############################################################### log4j.logger.response=ALL, proxyLog log4j.additivity.response=false ############################################################### ############################################################# # APPENDER ############################################################# # Direct log messages to a log file log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.File=C:\\log\\application.log log4j.appender.file.Threshold = ALL log4j.appender.file.MaxFileSize=10MB log4j.appender.file.MaxBackupIndex=1 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 # Direct log messages to stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Threshold = ALL 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 # Direct log messages to a log file log4j.appender.proxyLog=org.apache.log4j.RollingFileAppender log4j.appender.proxyLog.Threshold = ALL log4j.appender.proxyLog.File=C:\\log\\proxyLog.log log4j.appender.proxyLog.MaxFileSize=10MB log4j.appender.proxyLog.MaxBackupIndex=1 log4j.appender.proxyLog.layout=org.apache.log4j.PatternLayout log4j.appender.proxyLog.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n 

I use Tomcat as Application Server and I launch it with parameter -Dlog4j.configuration="log4j-DEV.properties"

When application starts, the file C:\log\application.log and C:\log\proxyLog.log are created but are empty although application writes log with instruction:

Log log = LogFactory.getLog(getClass()); log.info("Test log"); 

What is wrong?

Thanks all

5
  • I write the log appender file like: log4j.appender.toFile.File = logs/resourcepie_logfile.html, notice the forward leaning single slash, and i get a log file Commented Apr 26, 2015 at 19:20
  • @svarog I changed the path using forward leaning but the result it's the same: the file is created but it's empty. Commented Apr 26, 2015 at 19:31
  • could you provide a code sample with imports of how you're using the logger ? Commented Apr 26, 2015 at 19:41
  • 1
    I solved the issue changing the code in this way: Logger logger = null; logger = Logger.getRootLogger(); logger.info("TEST"); Commented Apr 26, 2015 at 19:49
  • If you can find out why exactly it works like that, then please post it as an answer. btw, i'm using log manager like: private static final Logger logger = LogManager.getLogger(ClassName.class.getName()); and i'm kind of curious as of why it works Commented Apr 26, 2015 at 19:56

1 Answer 1

3

I changed my code from:

Log log = LogFactory.getLog(getClass()); log.info("Test log"); 

to

Logger logger = null; logger = Logger.getRootLogger(); logger.info("TEST"); 

The log4j configuration was fine, I changed the behavior of application in order to use directly log4j classes and now the log appears correctly.

Thanks

Sign up to request clarification or add additional context in comments.

1 Comment

I was using sl4j and it happened to be more hard to use than l4j directly!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.