[logback]程序退出时flush log

原文:http://stackoverflow.com/questions/3678755/do-i-need-to-flush-events-when-shutting-down-using-logback

Here's a simple approach:

import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.LoggerContext;

...

ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
// Check for logback implementation of slf4j
if (loggerFactory instanceof LoggerContext) {
    LoggerContext context = (LoggerContext) loggerFactory;
    context.stop();
}

 

你可能感兴趣的:(logback)