Last active
April 6, 2023 16:45
-
-
Save fclairamb/5298705 to your computer and use it in GitHub Desktop.
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...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> |
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
Thank you very much
Thankyou so much
@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
thankyou very much