Chris Beams This issue is tougher than I expected. Some simple statements executed during logback initialization, e.g. loops on lists with 3 or 4 elements take 20 milliseconds, but would probably cost only a few nanoseconds later in the application lifecycle. Joran could be made to be quicker but that is not a simple undertaking.
Another way to reduce logback's impact on application start up is to skip configuration using Joran (with a configuration file that needs to be looked up) and instead configure logback programmatically with a Configurator specified under META-INF/services/ch.qos.logback.classic.spi.Configurator. In a recent commit, I modified BasicConfigurator to conform to the the Configurator interface.
Here is a very simple app to measure logback's impact on app start up time.
public class Main {
static public void main(String[] args) throws Exception {
long start = System.nanoTime();
Logger logger = LoggerFactory.getLogger("a");
long end = System.nanoTime();
long diff = (end-start)/1000/1000;
System.out.print("elapsed time in milli-seconds "+diff);
}
}
To enable BasicConfigurator, just add the line "ch.qos.logback.classic.BasicConfigurator" in the file META-INF/services/ch.qos.logback.classic.spi.Configurator. To enable another configurator you would add its fqcn in the aforementioned services file.
|