I am attempting to set up asynchronous logging (for performance reasons) within REST web methods that currently run in a liberty profile server.
In order to do this, I h
My problem is that no matter where I do this, sometimes it works and logging is very fast, and sometimes it doesn't.
Add that code in a static initializer block in the class that defines your main entry point.
public class MainClass {
// NOTE: Nothing can appear before this initializer
// NOTE: This initializer must be in the class that contains your entry point
static {
System.setProperty("Log4jContextSelector",
"org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
}
public static void main(final String[] args) {
// Do anything you want to here
}
}
According to the Java specification, static initialization occurs in the order it is declared. Therefore, the System.setProperty
call is guaranteed to happen before the Log4j initialization.