Skip to content

Instantly share code, notes, and snippets.

@AshwinJay
Last active August 6, 2018 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AshwinJay/5510965 to your computer and use it in GitHub Desktop.
Save AshwinJay/5510965 to your computer and use it in GitHub Desktop.
Log4J settings
BasicConfigurator.configure();
org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO);
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
loggerContext.reset();
PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setPattern("%msg%n");
ple.setContext(loggerContext);
ple.start();
ConsoleAppender console = new ConsoleAppender();
console.setEncoder(ple);
console.setContext(loggerContext);
console.start();
Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
rootLogger.setLevel(Level.INFO);
rootLogger.addAppender(console);
Before Jetty starts:
org.eclipse.jetty.util.log.Log.setLog(new org.eclipse.jetty.util.log.Slf4jLog());
Classpath:
lib/log4j2/2.0-beta4/log4j-api-2.0-beta4.jar
lib/log4j2/2.0-beta4/log4j-core-2.0-beta4.jar
lib/log4j2/2.0-beta4/log4j-slf4j-impl-2.0-beta4.jar
lib/slf4j/1.7.5/slf4j-api-1.7.5.jar
lib/slf4j/1.7.5/slf4j-ext-1.7.5.jar
@sarnobat
Copy link

sarnobat commented Aug 6, 2018

Programmatic logger configuration > xml-based logger configuration. If you use XML, you're giving the middle finger to the Java compiler which is there to HELP you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment