diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index e9da6eeca4..3ed9eea431 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -51,6 +51,7 @@ spring-boot-libraries spring-boot-libraries-2 spring-boot-process-automation + spring-boot-logging-logback spring-boot-logging-log4j2 spring-boot-mvc spring-boot-mvc-2 diff --git a/spring-boot-modules/spring-boot-logging-log4j2/pom.xml b/spring-boot-modules/spring-boot-logging-log4j2/pom.xml index 7178aeca32..b2a6975964 100644 --- a/spring-boot-modules/spring-boot-logging-log4j2/pom.xml +++ b/spring-boot-modules/spring-boot-logging-log4j2/pom.xml @@ -55,6 +55,10 @@ org.springframework.boot spring-boot-starter-log4j2 + + org.apache.logging.log4j + log4j-spring-boot + org.projectlombok lombok diff --git a/spring-boot-modules/spring-boot-logging-log4j2/src/main/java/com/baeldung/extensions/SpringBootLog4j2ExtensionsApplication.java b/spring-boot-modules/spring-boot-logging-log4j2/src/main/java/com/baeldung/extensions/SpringBootLog4j2ExtensionsApplication.java new file mode 100644 index 0000000000..7802653c1c --- /dev/null +++ b/spring-boot-modules/spring-boot-logging-log4j2/src/main/java/com/baeldung/extensions/SpringBootLog4j2ExtensionsApplication.java @@ -0,0 +1,25 @@ +package com.baeldung.extensions; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.PropertySource; + +@SpringBootApplication +@PropertySource("classpath:application-log4j2-extensions.properties") +public class SpringBootLog4j2ExtensionsApplication { + + private static final Logger logger = LogManager.getLogger(SpringBootLog4j2ExtensionsApplication.class); + + public static void main(String[] args) { + SpringApplication.run(SpringBootLog4j2ExtensionsApplication.class, args); + + logger.trace("Trace log message"); + logger.debug("Debug log message"); + logger.info("Info log message"); + logger.error("Error log message"); + logger.warn("Warn log message"); + logger.fatal("Fatal log message"); + } +} diff --git a/spring-boot-modules/spring-boot-logging-log4j2/src/main/resources/application-log4j2-extensions.properties b/spring-boot-modules/spring-boot-logging-log4j2/src/main/resources/application-log4j2-extensions.properties new file mode 100644 index 0000000000..8db25c3ff5 --- /dev/null +++ b/spring-boot-modules/spring-boot-logging-log4j2/src/main/resources/application-log4j2-extensions.properties @@ -0,0 +1,2 @@ +logging.config=classpath:log4j2-spring.xml +spring.application.name=log4j2-extension \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-logging-log4j2/src/main/resources/log4j2-spring.xml b/spring-boot-modules/spring-boot-logging-log4j2/src/main/resources/log4j2-spring.xml index 77a2074b30..c6906e1698 100644 --- a/spring-boot-modules/spring-boot-logging-log4j2/src/main/resources/log4j2-spring.xml +++ b/spring-boot-modules/spring-boot-logging-log4j2/src/main/resources/log4j2-spring.xml @@ -7,6 +7,11 @@ pattern="%style{%d{ISO8601}}{black} %highlight{%-5level }[%style{%t}{bright,blue}] %style{%C{1.}}{bright,yellow}: %msg%n%throwable" /> + + + + @@ -37,7 +42,20 @@ - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-logging-log4j2/src/main/resources/log4j2.system.properties b/spring-boot-modules/spring-boot-logging-log4j2/src/main/resources/log4j2.system.properties new file mode 100644 index 0000000000..ba79a90a64 --- /dev/null +++ b/spring-boot-modules/spring-boot-logging-log4j2/src/main/resources/log4j2.system.properties @@ -0,0 +1 @@ +log4j2.debug=true \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-logging-logback/.gitignore b/spring-boot-modules/spring-boot-logging-logback/.gitignore new file mode 100644 index 0000000000..d129c74ec9 --- /dev/null +++ b/spring-boot-modules/spring-boot-logging-logback/.gitignore @@ -0,0 +1,29 @@ +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/logs/ +/bin/ +/mvnw +/mvnw.cmd diff --git a/spring-boot-modules/spring-boot-logging-logback/README.md b/spring-boot-modules/spring-boot-logging-logback/README.md new file mode 100644 index 0000000000..0a9d6d8bba --- /dev/null +++ b/spring-boot-modules/spring-boot-logging-logback/README.md @@ -0,0 +1,6 @@ +## Spring Boot Logging with Logback + +This module contains articles about logging in Spring Boot projects with Logback. + +### Relevant Articles: + diff --git a/spring-boot-modules/spring-boot-logging-logback/pom.xml b/spring-boot-modules/spring-boot-logging-logback/pom.xml new file mode 100644 index 0000000000..deb591c9f0 --- /dev/null +++ b/spring-boot-modules/spring-boot-logging-logback/pom.xml @@ -0,0 +1,37 @@ + + + 4.0.0 + spring-boot-logging-logback + spring-boot-logging-logback + jar + Demo project for Spring Boot Logging with Logback + + + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-logging-logback/src/main/java/com/baeldung/extensions/SpringBootLogbackExtensionsApplication.java b/spring-boot-modules/spring-boot-logging-logback/src/main/java/com/baeldung/extensions/SpringBootLogbackExtensionsApplication.java new file mode 100644 index 0000000000..28e455a7ea --- /dev/null +++ b/spring-boot-modules/spring-boot-logging-logback/src/main/java/com/baeldung/extensions/SpringBootLogbackExtensionsApplication.java @@ -0,0 +1,22 @@ +package com.baeldung.extensions; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringBootLogbackExtensionsApplication { + + private static final Logger logger = LoggerFactory.getLogger(SpringBootLogbackExtensionsApplication.class); + + public static void main(String[] args) { + SpringApplication.run(SpringBootLogbackExtensionsApplication.class, args); + + logger.debug("Debug log message"); + logger.info("Info log message"); + logger.error("Error log message"); + logger.warn("Warn log message"); + logger.trace("Trace log message"); + } +} diff --git a/spring-boot-modules/spring-boot-logging-logback/src/main/resources/application.properties b/spring-boot-modules/spring-boot-logging-logback/src/main/resources/application.properties new file mode 100644 index 0000000000..d4860d5765 --- /dev/null +++ b/spring-boot-modules/spring-boot-logging-logback/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.application.name=logback-extension \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-logging-logback/src/main/resources/logback-spring.xml b/spring-boot-modules/spring-boot-logging-logback/src/main/resources/logback-spring.xml new file mode 100644 index 0000000000..b2bf8bcd07 --- /dev/null +++ b/spring-boot-modules/spring-boot-logging-logback/src/main/resources/logback-spring.xml @@ -0,0 +1,33 @@ + + + + + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + ${LOGS}/${application.name}.log + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + ${LOGS}/archived/${application.name}-%d{yyyy-MM-dd}.log + + + + + + + +