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

前端 未结 15 1146
情深已故
情深已故 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-04 23:54

    Stuffs I check to verify logging,

    1) Check that there're no older log4j versions.

    mvn dependency:tree | grep log ## ./gradlew dependencies | grep log
    [INFO] +- com.prayagupd:log-service:jar:1.0:compile
    [INFO] +- org.apache.logging.log4j:log4j-api:jar:2.6.2:compile
    [INFO] +- org.apache.logging.log4j:log4j-core:jar:2.6.2:compile
    [INFO] |  \- commons-logging:commons-logging:jar:1.1.1:compile
    

    2) make sure I'm setting log4j2.json properly, which is done with -Dlog4j.configurationFile=???

    val logConfig: PropertiesConfiguration = new PropertiesConfiguration("application.properties")
    System.setProperty("log4j.configurationFile", logConfig.getString("log4j.config.file"))
    
    println("log4j.configurationFile :: " + System.getProperty("log4j.configurationFile"))
    

    or

    Configurator.initialize(null, logConfig.getString("log4j.config.file"));
    

    Also if auto detection is happening make sure the file name is log4j2.* not log4j.*

    3) Another check is for parser for log4j2.json. Thanks log4j team for not providing parser within the API.

    
        com.fasterxml.jackson.core
        jackson-databind
        2.4.0
    
    

    This might throw an exception if can not find the json parser

    [Fatal Error] log4j2.json:1:1: Content is not allowed in prolog.
    

提交回复
热议问题