Last active
June 14, 2016 15:43
-
-
Save sobvan/75b55b0c7d02524cb163ed472d19f1c0 to your computer and use it in GitHub Desktop.
Simple code to initialize Log4j to only log to console. Useful in unit tests where you have log4j dependency in your code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.inepex.gist; | |
import org.apache.log4j.ConsoleAppender; | |
import org.apache.log4j.Logger; | |
import org.apache.log4j.PatternLayout; | |
import org.junit.Test; | |
public class Log4jToConsoleTest { | |
@Test | |
public void testRead() throws IOException { | |
ConsoleAppender ca = new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN), "System.out"); | |
Logger.getRootLogger().addAppender(ca); | |
logger.info("Hello console"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment