2

I can make the log to go the console but I cant seem to make it go to a log file. Here is my properties file.

log4j.rootLogger=DEBUG, LOG , stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%5p %d{d/MM/yy HH:mm:ss}:%m%n
# log4j.appender.LOG.Threshold=INFO

log4j.appender.LOG=org.apache.log4j.RollingFileAppender
log4j.appender.LOG.File=C:\dev\harry\data\logs\core.log
log4j.appender.LOG.layout=org.apache.log4j.PatternLayout
log4j.appender.LOG.Append=true
log4j.appender.LOG.layout.ConversionPattern=%5p %d{d/MM/yy HH:mm:ss}:%m%n
# log4j.appender.LOG.Threshold=INFO
Thang Pham
  • 38,125
  • 75
  • 201
  • 285
  • 1
    doesn't the \ have to be \\ ? That's true in most properties files – MJB May 10 '11 at 06:06
  • @MJB: Thank you. Your suggestion solved my problem. Can you format your comment into a separate answer so I can accept it. – Thang Pham May 16 '11 at 18:18

3 Answers3

5

The problem is that your single \ should be \\. This is true in most properties files.

joslinm
  • 7,845
  • 6
  • 49
  • 72
MJB
  • 9,352
  • 6
  • 34
  • 49
1

There are some issues with the \ in the file path that need to be fixed. The syntax is a bit cryptic but the way to log to multiple locations is to attach a named logging appender to the root logger. In this example this is:

log4j.rootLogger=DEBUG, LOG , stdout

DEBUG is a logging level (threshold filter) to use for the root logger.

LOG is the name of a logging appender

stdout is the name of a second appender

The logging appenders are specified by

log4j.appender.{logging-appender-name}={some.log4j.appender.class}
log4j.appender.{logging-appender-name}.{some-other-property}=...

Where {logging-appender-name} is a name selected by yourself (in this case LOG and stdout) and {some.log4j.appender.class} is one of the many log4j logging appender classes such as DailyRollingFileAppender or ConsoleAppender.

cyber-monk
  • 5,470
  • 6
  • 33
  • 42
0

I would have added: log4j.appender.LOG.Threshold=ALL

I'm not sure what the default is.

Olaf
  • 6,249
  • 1
  • 19
  • 37