Skip to content

Commit

Permalink
appender threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
Freund, Stephan authored and Freund, Stephan committed May 18, 2018
1 parent 1cbe1d6 commit 7ce2cdd
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ ${comments.log4jconfiguration}
<#if appender.clazz == "org.apache.log4j.FileAppender">
<File name="${appender.name}" fileName="${fileName}" append="${append}">
<PatternLayout pattern="${appender.layout.param?first.value}"/>
<#list appender.param as p>
<#if p.name == "Threshold">
<Filter type="ThresholdFilter" level="${p.value}"/>
</#if>
</#list>
</File>

</#if>
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/farnetto/log4jconverter/ConverterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,10 @@ private void convert(String file, OutputStream out)
fail(e.toString());
}
}

@Test
public void appenderThreshold()
{
convertAndCompare("appenderThreshold.xml");
}
}
63 changes: 63 additions & 0 deletions src/test/resources/in/log4j.appenderThreshold.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<!--
############################################################################
##
## This is the log configuration for production.
##
############################################################################
-->
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="true">

<!-- ====================================================================
application log
==================================================================== -->
<appender name="APPLICATION" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="logs/app.log"/>
<param name="Append" value="true"/>
<param name="MaxFileSize" value="75MB"/>
<param name="MaxBackupIndex" value="3"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%5p [%t] (%F:%L) - %m%n"/>
</layout>
</appender>

<appender name="FOO" class="org.apache.log4j.FileAppender">
<param name="File" value="logs/foo.log"/>
<param name="Append" value="false"/>
<param name="Threshold" value="ERROR" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%m%n"/>
</layout>
</appender>

<!-- ====================================================================
console log
==================================================================== -->
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%p %t %c - %m%n"/>
</layout>
</appender>

<!-- this is the logger for the converter package -->
<logger name="farnetto.log4jconverter" additivity="false">
<level value="DEBUG"/>
<appender-ref ref="APPLICATION" />
</logger>

<!-- this is another oneline comment -->
<logger name="farnetto">
<level value="WARN"/>
</logger>

<!-- ====================================================================
This is the root logger.
==================================================================== -->
<root>
<level value="INFO"/>
<appender-ref ref="CONSOLE"/>
<appender-ref ref="APPLICATION"/>
</root>

</log4j:configuration>
58 changes: 58 additions & 0 deletions src/test/resources/out/log4j2.appenderThreshold.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
############################################################################
##
## This is the log configuration for production.
##
############################################################################
-->
<Configuration status="debug">

<Appenders>

<!-- ====================================================================
application log
==================================================================== -->
<RollingFile name="APPLICATION" fileName="logs/app.log">
<PatternLayout pattern="%5p [%t] (%F:%L) - %m%n"/>
<Policies>
<SizeBasedTriggeringPolicy size="75MB"/>
</Policies>
<DefaultRolloverStrategy max="3"/>
</RollingFile>

<File name="FOO" fileName="logs/foo.log" append="false">
<PatternLayout pattern="%m%n"/>
<Filter type="ThresholdFilter" level="ERROR"/>
</File>

<!-- ====================================================================
console log
==================================================================== -->
<Console name="CONSOLE" target="STDOUT">
<PatternLayout pattern="%p %t %c - %m%n"/>
</Console>

</Appenders>

<Loggers>

<!-- this is the logger for the converter package -->
<Logger name="farnetto.log4jconverter" level="DEBUG" additivity="false">
<AppenderRef ref="APPLICATION"/>
</Logger>

<!-- this is another oneline comment -->
<Logger name="farnetto" level="WARN"/>

<!-- ====================================================================
This is the root logger.
==================================================================== -->
<Root level="root.level">
<AppenderRef ref="CONSOLE"/>
<AppenderRef ref="APPLICATION"/>
</Root>

</Loggers>

</Configuration>

0 comments on commit 7ce2cdd

Please sign in to comment.