How do I write error info in a separate file using log4j

user3575174 :

My log4j configuration below. I want to write error in a separate file. But if I use the configuration below error info is captured in both main log file as well as error log file. How to prevent error log being written into main log file?

# LOG4J configuration
log4j.rootLogger=DEBUG,Appender1,Appender2
log4j.appender.Appender1=org.apache.log4j.FileAppender
log4j.appender.Appender1.File=/Log/Main.log
log4j.appender.Appender1.layout=org.apache.log4j.PatternLayout
log4j.appender.Appender1.Threshold=info
log4j.appender.Appender1.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n
log4j.appender.Appender2=org.apache.log4j.FileAppender
log4j.appender.Appender2.File=/Log/Error.log
log4j.appender.Appender2.layout=org.apache.log4j.PatternLayout
log4j.appender.Appender2.Threshold=error
log4j.appender.Appender2.layout.ConversionPattern=%-7p %d [%t] %c %x - %m%n 
davidgiga1993 :

You can use the LevelMax and LevelMin configuration parameters for that

log4j.appender.Appender1.filter.a=org.apache.log4j.varia.LevelRangeFilter
log4j.appender.Appender1.filter.a.LevelMin=INFO
log4j.appender.Appender1.filter.a.LevelMax=WARN

log4j.appender.Appender2.filter.a=org.apache.log4j.varia.LevelRangeFilter
log4j.appender.Appender2.filter.a.LevelMin=ERROR
log4j.appender.Appender2.filter.a.LevelMax=ERROR

Related: https://stackoverflow.com/a/26768859/3542400

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to log INFO into one file and ERROR into another file using log4j in spring boot.

Using Log4J 1.*, how can I write two packages to two separate files?

How do I overwrite a log file in log4j?

how to write to a text file using to log4j?

How can I create 2 separate log files with one log4j config file?

How do I write a dictionary info a text file in this format? (Python)

How can i generate two logging with different logging level using Log4j config file

How do I create a log4j Logger using Spring XML configuration?

How do I turn logging off using log4j?

log4j, need to display only INFO and ERROR message in log file

Laravel : How to Log INFO to separate file

How do I setup log4j properties so that each thread outputs to its own log file?

How do I configure log4j to send log events to java.util.logging using JULAppender?

How do I get the properties or the info of a file using AppleScript?

How to log error and info messages separately into syslog with log4j?

How do I register an additional PropertySource with Log4j?

How do I configure log4j logging for a jar?

How do I adjust log4j levels at runtime?

How do I configure Log4J properly?

How to separate records in log file by blank line? Log4j

unable to write the logs to log file using log4j through Gradle

How do I remove the Tomcat INFO just from log file

How to separate a Log4j configuration?

log4j fails to write into file

How do I write inta a file and download the file using Javascript?

Why I obtain this FileNotFoundException when I try to use log4j to write into a file?

How to write log to file using slf4j

How to display Just D, I, E, F instead of DEBUG, INFO, ERRO, FATAL in log4j

How to redirect log4j logging from catalina.out to separate file?