0

I was analyzing the application logs and identified that there were a lot of debug logs coming from a class in one of the spring's libraries.

I have extended a class in spring which has turned on debug logs in the whole parent hierarchy if my custom class has log level set to debug.

I want to set log levels to debug for all my application specific classes while keeping rest all other classes to info.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Tushu
  • 1,866
  • 3
  • 14
  • 19

1 Answers1

0

Define two different loggers one at INFO level and one at DEBUG level in you log config file as below:

#Logger option with DEBUG for package1
log4j.logger.com.package1=DEBUG,DebugFileAppender

#Logger option with INFO for package1
log4j.logger.com.package1=INFO,InfoFileAppender

log4j.appender.DebugFileAppender=org.apache.log4j.FileAppender
log4j.appender.DebugFileAppender.File=debug.log
log4j.appender.DebugFileAppender.MaxFileSize=100MB
log4j.appender.DebugFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.DebugFileAppender.layout.ConversionPattern= %5p [%t] (%F:%L) - %m%n

log4j.appender.InfoFileAppender=org.apache.log4j.FileAppender
log4j.appender.InfoFileAppender.File=info.log
log4j.appender.InfoFileAppender.MaxFileSize=100MB
log4j.appender.InfoFileAppender.layout=org.apache.log4j.PatternLayout
log4j.appender.InfoFileAppender.layout.ConversionPattern= %5p [%t] (%F:%L) - %m%n
Yogendra Singh
  • 33,927
  • 6
  • 63
  • 73
  • I thought about this one but then this would not be convenient. If in future I extend some class I will have to make an entry in the log config file again. Is there any other option available like telling logging framework not to propagate log level up in the hierarchy? – Tushu Nov 16 '12 at 06:46
  • @Tushu: You can configure at package level not class level, right? That doesn't help? – Yogendra Singh Nov 16 '12 at 16:58
  • Configuring logging per package is definitely an option but that is not very convenient. Any unsuspecting user can extend a class without making an entry on the logging config file leading to a large amount of logs. What I am searching for is a way to prevent log level of parent class from being updated by the child class debug level. If I set rootlogger to INFO, then I want all other classes to stay at that level. – Tushu Nov 19 '12 at 08:22