How to initialize log4j properly?

前端 未结 24 3320
太阳男子
太阳男子 2020-11-22 06:49

After adding log4j to my application I get the following output every time I execute my application:

log4j:WARN No appenders could be found for logger (slideselec         


        
24条回答
  •  温柔的废话
    2020-11-22 06:57

    This is an alternative way using .yaml

    Logic Structure:

    Configuration:
        Properties:
        Appenders:
        Loggers:
    

    Sample:

    Configutation:
        name: Default
    
        Properties:
            Property:
                name: log-path
                value: "logs"
    
        Appenders:
    
            Console:
            name: Console_Appender
            target: SYSTEM_OUT
            PatternLayout:
                pattern: "[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n"
    
           File:
              name: File_Appender
              fileName: ${log-path}/logfile.log
              PatternLayout:
                pattern: "[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n"
    
        Loggers:
    
            Root:
                level: debug
                AppenderRef:
                  - ref: Console_Appender
    
            Logger:
                - name: ...<...>
                  level: debug
                  AppenderRef:
                     - ref: File_Appender
                     level: error             
    

    Ref: LOG4J 2 CONFIGURATION: USING YAML

提交回复
热议问题