What does mean sys:ls.logs in log4j?

Viewed 1045

I am reading log4j docs and logstash log4j config , i don't know ${sys:ls.logs} mean.

What mean ${sys:ls.logs}? How can i change this valuable in runtime or in OS environment. I use Ubuntu OS.

1 Answers

sys is System properties in Log4j 2. Log4j supports the syntax ${prefix:name} where the prefix identifies tells Log4j that variable name should be evaluated in a specific context. See Log4j 2 documents

sys : System properties. The formats are ${sys:some.property} and ${sys:some.property:-default_value}.

Property Support

You can reference properties in a configuration, Log4j will directly replace them, or Log4j will pass them to an underlying component that will dynamically resolve them. Properties come from values defined in the configuration file, system properties, environment variables, the ThreadContext Map, and data present in the event.

System properties are often defined outside the application and you can access them via a Lookup. You can further customize the property providers by adding their own Lookup Plugin. Default properties may also be specified in the Lookup by using the syntax ${lookupName:key:-defaultValue}.

    <Appenders>
      <File name="ApplicationLog" fileName="${sys:logPath:-/var/logs}/app.log"/>
    </Appenders>

Furthermore, using a lookup for the system property named ls.logs, in Log4j 1.x, the syntax would be ${ls.logs}. In Log4j 2, the syntax would be ${sys:ls.logs}.

This property may be set in app source or as an argument when start the service. For example, in a DefaultDeprecationLoggerTest for logstash in logstash source it is set to build/logs as below:

    @Before
    public void setUp() throws IOException {
        System.setProperty("log4j.configurationFile", CONFIG);
        System.setProperty("ls.log.format", "plain");
        System.setProperty("ls.logs", "build/logs");

        LogTestUtils.deleteLogFile("logstash-deprecation.log");
    }
Related