Problems using a <property> value in a routing appender

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Problems using a <property> value in a routing appender

Matt Sicker
I have the following log4j configuration, though it's failing at
runtime when a log message is logged due to the fileName attribute of
the rolling random access file appender is null despite that clearly
not being the case. I'll note that if I change the
AUDIT_LOG_DESTINATION property to refer to a constant value or just
removing the reference to ${FALLBACK_LOG_DESTINATION}, I don't get the
error anymore.

Config:

<Configuration status="DEBUG">
    <Properties>
        <Property
name="DEFAULT_HOME">$${env:JENKINS_HOME:-$${sys:JENKINS_HOME:-.}}</Property>
        <Property
name="FALLBACK_LOG_DESTINATION">${DEFAULT_HOME}/logs/audit.log</Property>
        <Property
name="AUDIT_LOG_DESTINATION">$${sys:auditFileName:-${FALLBACK_LOG_DESTINATION}}</Property>
        <Property
name="IANA_ENTERPRISE_NUMBER">$${sys:enterpriseNumber:-.}</Property>
        <Property
name="APPENDER_LAYOUT_TYPE">$${sys:appenderType:-fileAppender}</Property>
        <Property name="PORT">1854</Property>
        <Property name="HOST">localhost</Property>
    </Properties>

    <Appenders>

        <Routing name="Routing">
            <Routes pattern="$${sys:appenderType:-fileAppender}">
                <Route key="syslogAppender">
                    <!--This has to be configurable-->
                    <Syslog name="auditSyslog"
                            format="RFC5424"
                            host="${HOST}"
                            port="${PORT}"
                            protocol="TCP"
                            appName="ALP"
                            mdcId="mdc"
                            includeMDC="true"
                            facility="LOCAL0"
                            enterpriseNumber="${IANA_ENTERPRISE_NUMBER}"
                            newLine="true"
                            messageId="Server"
                            id="App"/>
                </Route>

                <Route key="fileAppender">
                    <RollingRandomAccessFile
                            name="auditFile"
                            fileName="${AUDIT_LOG_DESTINATION}"

filePattern="${AUDIT_LOG_DESTINATION}.%d{yyyyMMdd_HHmmss}-%i.log">

                        <JsonLayout properties="true"/>

                        <Policies>
                            <SizeBasedTriggeringPolicy size="20 MB"/>
                        </Policies>

                    </RollingRandomAccessFile>
                </Route>


            </Routes>
        </Routing>
    </Appenders>
    <Loggers>
        <Root level="debug">
            <AppenderRef ref="Routing"/>
        </Root>
    </Loggers>
</Configuration>


And the relevant debug log messages:

2019-06-20 14:11:16,925 Executor #0 for master : executing test #15
DEBUG Building Plugin[name=layout,
class=org.apache.logging.log4j.core.layout.JsonLayout].
2019-06-20 14:11:16,929 Executor #0 for master : executing test #15
DEBUG JsonLayout$Builder(propertiesAsList="null",
objectMessageAsJsonObject="null", ={}, eventEol="null",
compact="null", complete="null", locationInfo="null",
properties="true", includeStacktrace="null",
stacktraceAsString="null", includeNullDelimiter="null", ={},
charset="null", footerSerializer=null, headerSerializer=null,
Configuration(/Users/matt/code/audit-log-plugin/src/main/resources/log4j2.xml),
footer="null", header="null")
2019-06-20 14:11:17,146 Executor #0 for master : executing test #15
DEBUG PluginManager 'Converter' found 44 plugins
2019-06-20 14:11:17,147 Executor #0 for master : executing test #15
DEBUG Building Plugin[name=SizeBasedTriggeringPolicy,
class=org.apache.logging.log4j.core.appender.rolling.SizeBasedTriggeringPolicy].
2019-06-20 14:11:17,150 Executor #0 for master : executing test #15
DEBUG createPolicy(size="20 MB")
2019-06-20 14:11:17,152 Executor #0 for master : executing test #15
DEBUG Building Plugin[name=Policies,
class=org.apache.logging.log4j.core.appender.rolling.CompositeTriggeringPolicy].
2019-06-20 14:11:17,152 Executor #0 for master : executing test #15
DEBUG createPolicy(={SizeBasedTriggeringPolicy(size=20971520)})
2019-06-20 14:11:17,153 Executor #0 for master : executing test #15
DEBUG Building Plugin[name=appender,
class=org.apache.logging.log4j.core.appender.RollingRandomAccessFileAppender].
2019-06-20 14:11:17,156 Executor #0 for master : executing test #15
DEBUG RollingRandomAccessFileAppender$Builder(fileName="",
filePattern=".%d{yyyyMMdd_HHmmss}-%i.log", append="null",
Policies(CompositeTriggeringPolicy(policies=[SizeBasedTriggeringPolicy(size=20971520)])),
Strategy=null, advertise="null", advertiseURI="null",
filePermissions="null", fileOwner="null", fileGroup="null",
bufferedIo="null", bufferSize="null", immediateFlush="null",
ignoreExceptions="null",
JsonLayout(org.apache.logging.log4j.core.layout.JsonLayout@d0eda69),
name="auditFile",
Configuration(/Users/matt/code/audit-log-plugin/src/main/resources/log4j2.xml),
Filter=null, ={})
2019-06-20 14:11:17,168 Executor #0 for master : executing test #15
ERROR Cannot access RandomAccessFile java.io.FileNotFoundException:
(No such file or directory) java.io.FileNotFoundException:  (No such
file or directory)


--
Matt Sicker <[hidden email]>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]