I'm trying to create a conditional statement in my log4j2.xml
file and it does not seem to accept any of the conditional formatting. I've tried various options such as xslt etc. and it doesn't seem to work. Any help here would be great.
My intention is to create separate paths for logging, based on the operating system. I see that the appender error is because the MyRollingLog value has not be set. However it's the CLASS_NOT_FOUND
error that I'm not able to solve and the the invalid element
.
I'm getting the following error for this code...
2014-06-10 17:19:48,771 ERROR Error processing element then: CLASS_NOT_FOUND
2014-06-10 17:19:48,773 ERROR appenders contains an invalid element or attribute "if"
2014-06-10 17:19:48,776 ERROR Unable to locate appender MyRollingLog for logger com.xxx.xyz
Any help here would be great.
<?xml version="1.0" encoding="UTF-8"?>
<configuration status = "WARN">
<appenders>
<if>
<conditions>
<condition property="isMac">
<os family="mac" />
</condition>
</conditions>
<then>
<RollingFile name="MyRollingLog" fileName='../logs/CheckView.log'
filePattern="../logs/$${date:yyyy-MM}/CheckView-%d{MM-dd-yyyy}-%i.log.gz">
<PatternLayout>
<pattern>%d %p %m%n</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="15 MB"/>
</Policies>
<DefaultRolloverStrategy max="20"></DefaultRolloverStrategy>
</RollingFile>
</then>
</if>
<Console name="Console-out" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} %-5level %m%n"/>
</Console>
</appenders>
<loggers>
<logger name="com.xxx.xyz" level = "TRACE" additivity="false">
<appender-ref ref="MyRollingLog" />
</logger>
<root level = "ERROR">
<appender-ref ref="Console-out" />
</root>
</loggers>
</configuration>