diff --git a/logging-modules/log4j2/src/main/java/com/baeldung/logging/log4j2/consoleandfile/Log4j2ConsoleAndFile.java b/logging-modules/log4j2/src/main/java/com/baeldung/logging/log4j2/consoleandfile/Log4j2ConsoleAndFile.java new file mode 100644 index 0000000000..56119efd9e --- /dev/null +++ b/logging-modules/log4j2/src/main/java/com/baeldung/logging/log4j2/consoleandfile/Log4j2ConsoleAndFile.java @@ -0,0 +1,14 @@ +package com.baeldung.logging.log4j2.consoleandfile; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public class Log4j2ConsoleAndFile { + + private static final Logger logger = LogManager.getLogger(Log4j2ConsoleAndFile.class); + + public static void main(String[] args) { + logger.info("Hello World!"); + logger.debug("Hello World!"); + } +} diff --git a/logging-modules/log4j2/src/main/resources/log4j2.properties b/logging-modules/log4j2/src/main/resources/log4j2.properties new file mode 100644 index 0000000000..1d31dd55b5 --- /dev/null +++ b/logging-modules/log4j2/src/main/resources/log4j2.properties @@ -0,0 +1,14 @@ +appender.console.type = Console +appender.console.name = STDOUT +appender.console.layout.type = PatternLayout +appender.console.layout.pattern = [%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n + +appender.file.type = File +appender.file.name = LOGFILE +appender.file.fileName=logs/log4j.log +appender.file.layout.type=PatternLayout +appender.file.layout.pattern=[%-5level] %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %c{1} - %msg%n +appender.file.filter.threshold.type = ThresholdFilter +appender.file.filter.threshold.level = info + +rootLogger=debug, STDOUT, LOGFILE \ No newline at end of file