Skip to content

Instantly share code, notes, and snippets.

@rocketraman
Last active January 19, 2018 00:09
Show Gist options
  • Select an option

  • Save rocketraman/05eab786d5a172ff80b9a909d5587d3a to your computer and use it in GitHub Desktop.

Select an option

Save rocketraman/05eab786d5a172ff80b9a909d5587d3a to your computer and use it in GitHub Desktop.

Revisions

  1. rocketraman revised this gist Jan 19, 2018. 2 changed files with 19 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions TestLogging.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    import org.apache.logging.log4j.LogManager;
    import org.apache.logging.log4j.Logger;

    public class TestLogging {
    private static final Logger logger = LogManager.getLogger("HelloWorld");

    public static void main(String[] args) {
    logger.info("Start");
    logger.info("This is a test.", new Exception("Test exception!"));
    logger.info("End");
    }
    }
    7 changes: 7 additions & 0 deletions stdout.log
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    2018-01-18 18:58:05,157 | Start
    2018-01-18 18:58:05,160 | This is a test. | EXCEPTION: java.lang.Exception: Test exception!
    at TestLogging.main(TestLogging.java:9)

    java.lang.Exception: Test exception!
    at TestLogging.main(TestLogging.java:9) [classes/:?]
    2018-01-18 18:58:05,164 | End
  2. rocketraman revised this gist Jan 18, 2018. No changes.
  3. rocketraman created this gist Jan 18, 2018.
    13 changes: 13 additions & 0 deletions log4j2-2196.xml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    <?xml version="1.0" encoding="UTF-8"?>
    <Configuration status="warn">
    <Appenders>
    <Console name="Console" target="SYSTEM_OUT" direct="true">
    <PatternLayout pattern="%d{DEFAULT} | %msg%varsNotEmpty{ | EXCEPTION: %throwable}%n"/>
    </Console>
    </Appenders>
    <Loggers>
    <Root level="debug">
    <AppenderRef ref="Console"/>
    </Root>
    </Loggers>
    </Configuration>