Last active
September 23, 2019 15:44
-
-
Save jonathansanchez/1c11ef1e8e70acf57d7989ee70b9775e to your computer and use it in GitHub Desktop.
Log4j2 In Spring Boot
This file contains hidden or 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> | |
<Appenders> | |
<Console name="Console" target="SYSTEM_OUT"> | |
<PatternLayout | |
pattern="%style{%d{ISO8601}}{black} %highlight{%-5level }[%style{%t}{bright,blue}] %style{%C{1.}}{bright,yellow}: %msg%n%throwable" /> | |
</Console> | |
<RollingFile name="RollingFile" | |
fileName="./log/app.log" | |
filePattern="./log/app-%d{yyyy-MM-dd}-%i.log"> | |
<!-- If you want compress --> | |
<!--filePattern="./log/$${date:yyyy-MM}/app-%d{-dd-MMMM-yyyy}-%i.log.gz">--> | |
<PatternLayout> | |
<pattern>%d %p %C{1.} [%t] %m%n</pattern> | |
</PatternLayout> | |
<Policies> | |
<OnStartupTriggeringPolicy /> | |
<SizeBasedTriggeringPolicy | |
size="10 MB" /> | |
<TimeBasedTriggeringPolicy /> | |
</Policies> | |
</RollingFile> | |
</Appenders> | |
<Loggers> | |
<AsyncLogger name="com.some.package" level="debug" additivity="false"> | |
<AppenderRef ref="Console" /> | |
<AppenderRef ref="RollingFile" /> | |
</AsyncLogger> | |
<Root level="info"> | |
<AppenderRef ref="Console" /> | |
<AppenderRef ref="RollingFile" /> | |
</Root> | |
<Logger name="com.some.package" level="trace"></Logger> | |
</Loggers> | |
</Configuration> |
This file contains hidden or 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"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<parent> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-parent</artifactId> | |
<version>2.1.8.RELEASE</version> | |
<relativePath/> <!-- lookup parent from repository --> | |
</parent> | |
<groupId>com.camelsecure</groupId> | |
<artifactId>notifier</artifactId> | |
<version>0.0.1-SNAPSHOT</version> | |
<name>App</name> | |
<description>Service App</description> | |
<properties> | |
<java.version>1.8</java.version> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-web</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter</artifactId> | |
<exclusions> | |
<exclusion> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-logging</artifactId> | |
</exclusion> | |
</exclusions> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-log4j2</artifactId> | |
</dependency> | |
</dependencies> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-maven-plugin</artifactId> | |
</plugin> | |
</plugins> | |
<finalName>app</finalName> | |
</build> | |
</project> |
This file contains hidden or 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
package com.some.package; | |
import org.apache.logging.log4j.LogManager; | |
import org.apache.logging.log4j.Logger; | |
public class SomeClass { | |
private static final Logger logger = LogManager.getLogger(SomeClass.class); | |
public void someMethod() { | |
logger.debug("Debugging log"); | |
logger.info("Info log"); | |
logger.warn("Warning log"); | |
logger.error("Error log"); | |
logger.fatal("Fatal log"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment