Reputation: 1199
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.
Upvotes: 0
Views: 341
Reputation: 7324
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:
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
Upvotes: 1