Java Code Examples for ch.qos.logback.classic.util.ContextInitializer#autoConfig()

The following examples show how to use ch.qos.logback.classic.util.ContextInitializer#autoConfig() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSmartClient.java    From SmartIM with Apache License 2.0 6 votes vote down vote up
@Override
public void setWorkDir(File path) {
    if (path == null) {
        throw new IllegalArgumentException("Work directory is null");
    }
    if (!path.exists()) {
        path.mkdirs();
    }
    this.workDir = path;
    System.setProperty("log.home", path.getAbsolutePath());
    ILoggerFactory fac = LoggerFactory.getILoggerFactory();
    if (fac != null && fac instanceof LoggerContext) {
        LoggerContext lc = (LoggerContext) fac;
        lc.getStatusManager().clear();
        lc.reset();
        lc.putProperty("log.home", path.getAbsolutePath());
        ContextInitializer ci = new ContextInitializer(lc);
        try {
            ci.autoConfig();
        } catch (JoranException e) {
            e.printStackTrace();
        }
    }
}
 
Example 2
Source File: BaseCommand.java    From emissary with Apache License 2.0 5 votes vote down vote up
private void doLogbackReinit(LoggerContext loggerContext, String configFilePath) {
    System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, configFilePath);
    loggerContext.reset();
    ContextInitializer newContext = new ContextInitializer(loggerContext);
    try {
        newContext.autoConfig();
    } catch (JoranException e) {
        LOG.error("Problem reconfiguring logback with {}", getLogbackConfig(), e);
    }
}
 
Example 3
Source File: SampleApplication.java    From cukes with Apache License 2.0 5 votes vote down vote up
public static void overrideLogging() {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    context.reset();
    ContextInitializer initializer = new ContextInitializer(context);
    try {
        initializer.autoConfig();
    } catch (JoranException ignored) {}
}