sahan
sahan

Reputation: 41

Can we set the specified appender in log4j.properties in the code

I have several apenders in log4j.properties. Is there way to give specified apender for logger call

Upvotes: 2

Views: 470

Answers (1)

Nishant
Nishant

Reputation: 55866

Oh sure you can. You can explicitly call an appender by name.

So, if you have your appender like

log4j.logger.MyLog=DEBUG, mylog
#additivity false, means just don't append to default root logger as well
log4j.additivity.MyLog=false
#other usual props
log4j.appender.mylog=org.apache.log4j.RollingFileAppender
log4j.appender.mylog.maxFileSize=5000KB
log4j.appender.mylog.maxBackupIndex=3

Now, in your class use this appender like

Logger log = Logger.getLogger("MyLog");

You're done.

Upvotes: 2

Related Questions