log4j2: Location for setting Log4jContextSelector system property for asynchronous logging

前端 未结 4 1907
被撕碎了的回忆
被撕碎了的回忆 2021-02-05 17:45

I am attempting to set up asynchronous logging (for performance reasons) within REST web methods that currently run in a liberty profile server.

In order to do this, I h

4条回答
  •  情歌与酒
    2021-02-05 18:45

    There is an undocumented method of setting this value for your project without having to manually pass in the system property value during start up.

    Add a file named log4j2.component.properties to your classpath. This can be done in most maven or gradle projects by saving it in src/main/resources.

    This is file is simply java.util.Properties file. Set the value for the context selector by adding the following line to the file.

    Log4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector
    

    Log4j will attempt to read the system property first. If the system property is null, then it will fall back to the values stored in this file by default.

    The code that performs this setup is located at Log4jContextFactory.java:91.

提交回复
热议问题