0

I have a debug,info,warn,error logs in my code. But i want to print only info,error logs in my console. I want to store all the logs in a file. Can anyone suggest a way.

I trie with

log4j.rootLogger=debug,R1,R2

log4j.appender.R1=org.apache.log4j.ConsoleAppender
log4j.appender.R1.layout=org.apache.log4j.PatternLayout
log4j.appender.R1.layout.ConversionPattern=%d{dd/MM/yy kk:mm:ss.SSS} %-5p [%t] %x (%F:%L) - %m%n


#OAPIFacade front logs
log4j.appender.R2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R2.File=app/log4j/prop/log4j.log
log4j.appender.R1.DatePattern='.'dd-MM-yy
log4j.appender.R2.layout=org.apache.log4j.PatternLayout
log4j.appender.R2.layout.ConversionPattern=%d{dd/MM/yy kk:mm:ss.SSS} %-5p [%t] %x (%F:%L) - %m%n

In this case, all the logs are printing in the console, but i want only info and error logs in the console.

BKK
  • 1,199
  • 6
  • 16
  • 24
  • The answers below are correct- for more information on the difference between setting the threshold and setting the logger level, you may see: http://stackoverflow.com/a/5120069/751634 – Jensen Ching Oct 09 '12 at 05:58

1 Answers1

1

As far as I know, you can't see INFO, hide WARN, and see ERROR at the same time; this violates the design of the log levels. The levels are defined in this order:

  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • FATAL

However, if you wanted to see only WARN and ERROR in the console, you can do this using the Threshold setting of the appender. Specifically, you just need to add:

log4j.appender.R1.Threshold=WARN
Cory Kendall
  • 7,195
  • 8
  • 37
  • 64