Skip to content

Instantly share code, notes, and snippets.

@cenkc
Created March 7, 2019 06:53
Show Gist options
  • Save cenkc/570da7e615894b16a22906f24e5c909a to your computer and use it in GitHub Desktop.
Save cenkc/570da7e615894b16a22906f24e5c909a to your computer and use it in GitHub Desktop.
Log4j without properties file
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