开发者

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

开发者 https://www.devze.com 2023-02-15 16:26 出处:网络
I have several apenders in log4j.properties. 开发者_运维知识库Is there way to give specified apender for logger callOh sure you can. You can explicitly call an appender by name.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消