How to configure Logger Programmatically in log4j2.02?

后端 未结 3 403
北恋
北恋 2021-02-05 14:05

I want to use log4j without any configure file. What I wan to do is something as:

logger = (Logger) LogManager.getLogger(this.getClass());
Strin         


        
3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-05 14:52

    With the latest version of log4j2, all create the APIs like

    PatternLayout.createLayout, 
    FileAppender.createAppender, 
    LoggerConfig.createLogger 
    

    have become deprecated, it's better to use a custom log ConfigurationFactory along with ConfigurationBuilder for defining the log configuration programmatically.

提交回复
热议问题