Hi, I am implementing a new FileAppender which I would like to contribute to the community. Please let me know if it would be interesting for you and how I could submit my implementation.
The appender allows you to log messages of a specific level (see Threshold parameter). However, if a LoggingEvent with level >= ERROR occurs, all related lower level messages are printed out as well. For this reason, I am going to write a FileAppender which extends DailyRollingFileAppender and - writes out all logging messages as configured - buffers (buffer size is configurable) all messages from the lower level including the LoggingEvent which are logged out anyway (to provide better context) - and outputs the entire buffer when a log message with level >= ERROR occurs The buffer is cleared whenever a context switch (NDC) occurs. The configuration might look as follows: <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <appender name="default" class="de.zalando.log.backend.appender.BufferingFileAppender"> <param name="File" value="application.log"/> <param name="Append" value="true"/> <param name="encoding" value="UTF-8"/> <param name="encoding" value="UTF-8"/> <param name="Threshold" value="INFO“/> <!-- determines logging level of appender -> control what data received from the logger should be print out as usual + DEBUG is default --> <param name="BufferLevels" value="DEBUG"/> <!-— comma separated list of levels which should be buffered determines which data should be logged until ERROR or FATAL occurs NOTE: level specified in Threshold does not have to be specified + DEBUG is default --> <param name=„BufferSize“ value="10000“ <!— up to 10000 recent messages are buffered NOTE: 1000 is default —> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d %x %p %t %l: %m%n"/> </layout> </appender> <root> <priority value="DEBUG"/> <!-- LEVEL of the logger -> level determines which logging events reach the appender --> <appender-ref ref="default" /> </root> </log4j:configuration> Best regards, Benni -- Benjamin Friedrich Java Developer Logistics - Outbound Zalando AG POSTANSCHRIFT Zalando SE 11501 Berlin STANDORT Zalando SE Sonnenburger Str. 73 10437 Berlin Germany Fax: +493027594693 E-Mail: benjamin.friedr...@zalando.de Web: www.zalando.de Jobs: jobs.zalando.de Zalando SE, Tamara-Danz-Straße 1, 10243 Berlin Handelsregister: Amtsgericht Charlottenburg, HRB 158855 B Steuer-Nr. 37/125/21423 * USt-ID-Nr. DE 260543043 Vorstand: Robert Gentz, David Schneider, Rubin Ritter Vorsitzende des Aufsichtsrates: Cristina Stenbeck Sitz der Gesellschaft: Berlin