Skip to content

Instantly share code, notes, and snippets.

@kathyrollo
Created April 24, 2020 15:26
Show Gist options
  • Save kathyrollo/4346deb94046771cd51199be2b74dc6c to your computer and use it in GitHub Desktop.
Save kathyrollo/4346deb94046771cd51199be2b74dc6c to your computer and use it in GitHub Desktop.
SLF4J with Log4j2
<?xml version="1.0" encoding="UTF-8" ?>
<Configuration status="WARN">
<Properties>
<Property name="logPath">target/test-logs</Property>
<Property name="rollingFileName">test-log</Property>
</Properties>
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="[%highlight{%-5level}] %d{DEFAULT} %c{1}.%M() - %msg%n%throwable{short.lineNumber}" />
</Console>
<RollingFile name="rollingFile" fileName="${logPath}/${rollingFileName}.log" filePattern="${logPath}/${rollingFileName}_%d{yyyy-MM-dd}.log">
<PatternLayout pattern="[%highlight{%-5level}] %d{DEFAULT} %c{1}.%M() - %msg%n%throwable{short.lineNumber}" />
<Policies>
<!-- Causes a rollover if the log file is older than the current JVM's start time -->
<OnStartupTriggeringPolicy />
<!-- Causes a rollover once the date/time pattern no longer applies to the active file -->
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
</Policies>
</RollingFile>
</Appenders>
<Loggers>
<Root level="DEBUG" additivity="false">
<AppenderRef ref="console" />
<AppenderRef ref="rollingFile" />
</Root>
</Loggers>
</Configuration>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>${slf4j}</version>
</dependency>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment