Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
log4j2.xml sample setup files: * rolling: To enable rolling logging. * setup file to log on file (rotation should be handled by logrote), syslog (to collect all the logs from the different services) and console...
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<properties>
<property name="name">app</property>
<property name="pattern">%d{yyyy-MM-dd HH:mm:ss.SSS} | %-5.5p | %-10.10t | %-20.20C:%-5.5L | %msg%n</property>
<!--
It will look like that:
2013-04-03 07:37:51.993 | WARN | main | lnetgateway.Server:56 | My app is logging stuff
-->
</properties>
<appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="${pattern}"/>
</Console>
<RollingFile name="RollingFile" fileName="logs/${name}.log"
filePattern="logs/$${date:yyyy-MM}/${name}-%d{yyyy-MM-dd}-%i.log.gz">
<PatternLayout>
<pattern>${pattern}</pattern>
</PatternLayout>
<Policies>
<TimeBasedTriggeringPolicy /><!-- Rotated everyday -->
<SizeBasedTriggeringPolicy size="100 MB"/> <!-- Or every 100 MB -->
</Policies>
</RollingFile>
</appenders>
<loggers>
<root level="debug"> <!-- We log everything -->
<appender-ref ref="Console"/> <!-- To console -->
<appender-ref ref="RollingFile"/> <!-- And to a rotated file -->
</root>
</loggers>
</configuration>
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<properties>
<property name="servicename">m2mp_checker</property>
<property name="filename">/var/log/m2mp/${servicename}.log</property>
<property name="patternTime">%d{yyyy-MM-dd HH:mm:ss.SSS} | %-5.5p | %-10.10t | %-20.20C:%-5.5L | %msg%n</property>
<property name="patternNoTime">%-5.5p | %-10.10t | %-20.20C:%-5.5L | %msg%n</property>
</properties>
<appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="${patternTime}"/>
</Console>
<File name="file" fileName="${filename}">
<PatternLayout pattern="${patternTime}"/>
</File>
<Syslog name="syslog" host="localhost" port="514" protocol="UDP" appName="${servicename}">
</Syslog>
</appenders>
<loggers>
<root level="info">
<appender-ref ref="file"/>
<appender-ref ref="console"/>
<appender-ref ref="syslog"/>
</root>
</loggers>
</configuration>
@juapar2

This comment has been minimized.

Copy link

@juapar2 juapar2 commented Mar 11, 2015

Thanks very self explainatory

@terexwizard

This comment has been minimized.

Copy link

@terexwizard terexwizard commented Jun 7, 2017

thankyou very much

@Moataz-Hammous

This comment has been minimized.

Copy link

@Moataz-Hammous Moataz-Hammous commented Jan 30, 2018

Hello
I have tried syslog /var/log/ in my application and i got the following error Could not create directory "/private/var/log/m2mp" when i run my app

@adiparwira

This comment has been minimized.

Copy link

@adiparwira adiparwira commented Mar 5, 2018

Thank you very much

@neel06shah

This comment has been minimized.

Copy link

@neel06shah neel06shah commented Jul 23, 2021

Thankyou so much

@fclairamb

This comment has been minimized.

Copy link
Owner Author

@fclairamb fclairamb commented Jul 23, 2021

@neel06shah you're welcome. I completely forgot about this 😸

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment