Merge pull request #7714 from dhruba619/master

BAEL-2974 Logger vs System.out
This commit is contained in:
Erik Pragt 2019-10-02 21:16:41 +10:00 committed by GitHub
commit 8db8202cdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 2 deletions

View File

@ -0,0 +1,18 @@
package com.baeldung.logging.log4j2;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
public class Log4j2ComparisonSysout {
public static void main(String[] args) throws FileNotFoundException {
PrintStream outStream = new PrintStream(new File("outFile.txt"));
System.setOut(outStream);
System.out.println("This is a baeldung article");
PrintStream errStream = new PrintStream(new File("errFile.txt"));
System.setErr(errStream);
System.err.println("This is a baeldung article error");
}
}

View File

@ -0,0 +1,19 @@
package com.baeldung.logging.log4j2;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
public class Log4j2Example {
private static final Logger logger = LogManager.getLogger(Log4j2Example.class);
public static void main(String[] args) {
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");
logger.trace("Trace log message");
}
}

View File

@ -5,8 +5,7 @@
<xi:include
href="log4j2-includes/console-appender_pattern-layout_colored.xml" />
<Console name="ConsoleAppender" target="SYSTEM_OUT">
<PatternLayout
pattern="%d [%t] %-5level %logger{36} - %msg%n%throwable" />
<PatternLayout pattern="%style{%date{DEFAULT}}{yellow} %highlight{%-5level}{FATAL=bg_red, ERROR=red, WARN=yellow, INFO=green} %message"/>
</Console>
<Console name="ConsoleRedAppender" target="SYSTEM_OUT">
<PatternLayout pattern="%style{%message}{red}%n" />