BAEL-5677 - Logging to both file and console with log4j (#12550)

* BAEL-5677 - Logging to both file and console with log4j

* Moving from log4j to log4j2

* Correction in class name

* Moving to log4j2 package
This commit is contained in:
Abhinav Pandey 2022-08-17 09:35:59 +05:30 committed by GitHub
parent ff63982af2
commit 72409da627
2 changed files with 28 additions and 0 deletions

View File

@ -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!");
}
}

View File

@ -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