No log4j2 configuration file found. Using default configuration: logging only errors to the console

前端 未结 15 1137
情深已故
情深已故 2020-12-04 22:59
$ java -Dlog4j.configuration=file:///path/to/your/log4j2.xml -jar /path/to/your/jar_file.jar

Written to the console, you get

ERROR          


        
15条回答
  •  佛祖请我去吃肉
    2020-12-05 00:05

    Problem 1

    ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
    

    Solution 1

    To work with version 2 of log4j aka "log4j2"

    -Dlog4j.configuration=
    

    should read

    -Dlog4j.configurationFile=
    
    • 1.2 manual: http://logging.apache.org/log4j/1.2/manual.html
    • 2.x manual: http://logging.apache.org/log4j/2.x/manual/configuration.html

    Problem 2

    log4j:WARN ....
    

    Solution 2

    In your project, uninclude the log4j-1.2 jar and instead, include the log4j-1.2-api-2.1.jar. I wasn't sure how exactly to exclude the log4j 1.2. I knew that what dependency of my project was requiring it. So, with some reading, I excluded a bunch of stuff.

    
        org.apache.kafka
        kafka_2.10
        0.8.2.0
        
            
                org.apache.logging.log4j
                log4j-core                
            
            
                org.apache.log4j
                log4j-core
            
            
                log4j
                log4j
                      
        
    
    

    I am not sure which of the exclusions did the trick. Separately, I included a dependency to the 1.2 api which bridges to 2.x.

    
    
        org.apache.logging.log4j
        log4j-1.2-api
        2.2
    
    

    Now, the 1.2 logs which were only going to the console actually flow to our 2.x appenders.

提交回复
热议问题