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
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.
精彩评论