Pregunta

i have the following log4j configuration:

# Root logger option
log4j.rootLogger=file, stdout

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.Threshold=WARN
log4j.appender.file.File=logs/log.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.Append=true
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=INFO
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

Logging into stdout works fine but nothing is logged into my file. There are definately outputs for the file but nothing happens.

Why isnt he logging into my file?

¿Fue útil?

Solución

you can change your configuration file like this.

# Root logger option
log4j.rootLogger= ALL,file, stdout

And log4j.appender.stdout.Threshold=INFO change level like ALL its print all level logs TRACE to FATAL

Otros consejos

One reason could be that the Threshold for the stdout appender(INFO) is lower than the file appender(WARN). So, if there are only INFO messages being logged, you will only see them in the stdout and not in the file.

It depends on how you are running it. Is this just a normal java program? For example, if you are trying to run it within a container (such as Karaf) then sometimes they can have special log destinations set.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top