Log4J2 property substitution - default

You can use the same ${sys:propName:-default}syntax. Notice the ':-', it is is called "variable default value delimiter". The default value for the "variable default value delimiter" is :-, as in bash and other *nix shells.

You can read more about this in the Log4j 2 documentation for the StrSubstitutor class.

To use the same example:

<Configuration status="debug">
  ...
    <Appenders>
        <Appender type="File" name="File"
                  fileName="${sys:oauthLoginLogPath:-default/location/of/oauth2.log}">
        ....
    </Appenders>
</Configuration>

Default Property map

Looking at http://logging.apache.org/log4j/2.x/manual/configuration.html#PropertySubstitution you can specify a default property map in the configuration file. That takes this form:

<Configuration status="debug">
  <Properties>
    <Property name="oauthLoginLogPath">default/location/of/oauth2.log</Property>
  </Properties>
  ...
  <Appenders>
    <Appender type="File" name="File" fileName="${sys:oauthLoginLogPath}">
    ....
</Configuration

Then, if you start your app with system property -DoauthLoginLogPath=/path/oauth2.log, the File appender fileName value will first be looked up in system properties, but if that fails, it will fall back to the property defined in the Properties section at the top of the log4j2.xml configuration file.

Inline

A second way is to provide the default value inline:

<Appender type="File" name="File" fileName="${sys:oauthLoginLogPath:-default/location/of/oauth2.log}">

Generally all Log4j2 lookups follow this pattern: ${type:key:-defaultValue}.

Env vs sys

By the way, the env prefix is for environment variables (like %PATH% on Windows), and is not related to sys, which is Java system properties. See also http://logging.apache.org/log4j/2.x/manual/lookups.html