Created
March 7, 2019 06:53
-
-
Save cenkc/570da7e615894b16a22906f24e5c909a to your computer and use it in GitHub Desktop.
Log4j without properties file
This file contains 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
import org.apache.log4j.*; | |
//below is the default conversion pattern | |
PatternLayout pl = new PatternLayout("%r [%t] %p %c %x - %m%n"); | |
Appender appender = new FileAppender(pl, "D:\\tmp\\hede.txt", false); | |
BasicConfigurator.configure(appender); | |
/* | |
// For direct output to console, use configure without appender | |
// it uses default pattern which mentioned up above | |
BasicConfigurator.configure(); | |
*/ | |
// set logging level | |
Logger.getRootLogger().setLevel(Level.INFO); | |
// Reference | |
// https://www.tutorialspoint.com/log4j/log4j_patternlayout.htm | |
// https://gist.github.com/riversun/45b86ccf08e1b5a076652aec33545ab4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment