LOG4J - Avoid the same message twice in the log

Here is my log4j.propertiesfile

# Set loggers' levels
log4j.rootLogger=warn, trace_file

# Appender
log4j.appender.trace_file=org.apache.log4j.RollingFileAppender
log4j.appender.trace_file.Append=true
log4j.appender.trace_file.File=log/myLog.log
log4j.appender.trace_file.MaxFileSize=10MB
log4j.appender.trace_file.MaxBackupIndex=50

# PatternLayout
log4j.appender.trace_file.layout=org.apache.log4j.PatternLayout
log4j.appender.trace_file.layout.ConversionPattern=%d [%p] (%F:%L) %m%n

# Classes
log4j.logger.my_package=info, trace_file

What I want:

  • Save log requests from my.packageat trace_filewith a level of at leastINFO
  • Save journal requests from all other registrars trace_fileONLY if it is at least WARNlevel

My configuration does not work. If it my.packageinvokes a level log request WARN, this log request is recorded twice. If I use two separate applications, there is no problem.

What am I missing?

+5
source share
6 answers

Try removing the trace_file directive from the my_package log statement.

+6
source

Edit

log4j.logger.my_package=info, trace_file

to

log4j.logger.my_package=info

, , trace_file my_package, .

+4

. .

, log4j.properties:

log4j.additivity.com.example.package=false. ( org.hibernate , )

, log4j.xml:

<logger name="com.example.package" additivity="false">
....
</logger>
+4

rootLogger.

my_package trace_file logguer log4j.rootLogger=warn, trace_file, appender log4j.logger.my_package=info, trace_file

, , rootLogger, ?

, root, appender

log4j.logger.my_package=info
+1

- :

log4j.additivity.my_package =

. http://logging.apache.org/log4j/1.2/manual.html, " ".

:

Appender C C . " ".

, C, P, , false, C C P, P.

.

+1

This looks like an additivity problem.

I am not familiar with the configuration of the properties file, but there must be a flag when defining the registrar additivity. Setting this parameter to falseshould solve the problem. In addition, using the xml configuration, you can use the log4j option Filter, which is not available in the properties file.

It should be something like this: log4j.logger.my_package.additivity = false

Finally, look at logback if you have never heard of this before

+1
source

All Articles