Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j multiple files

I have 2 logging files. I have defined two appenders for the 2 files. In a class, if i need to output few logs to one file, and few to the other, do i need to have 2 logger instances. Is there a cleaner way of achieving this requirement? Or is there some log4j configuration that will help me?

like image 903
Pooja Avatar asked Oct 14 '22 21:10

Pooja


1 Answers

You can create two named loggers like the following:

log4j.logger.system=debug, sys

log4j.appender.sys=org.apache.log4j.RollingFileAppender
log4j.appender.sys.file=/logs/system.log
log4j.appender.sys.maxFileSize=1MB
log4j.appender.sys.maxBackupIndex=25
log4j.appender.sys.layout=org.apache.log4j.PatternLayout
log4j.appender.sys.layout.conversionPattern=%d{MMM dd HH:mm:ss} %-5p (%F:%L) - %m%n

which you can locate and use from code:

Logger.getLogger("system").debug("...");
like image 51
cherouvim Avatar answered Nov 08 '22 22:11

cherouvim