ch.qos.logback.classic.BasicConfigurator Java Examples

The following examples show how to use ch.qos.logback.classic.BasicConfigurator. 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: ContextInitializer.java    From stategen with GNU Affero General Public License v3.0 6 votes vote down vote up
public void autoConfig() throws JoranException ,IOException{
    StatusListenerConfigHelper.installIfAsked(loggerContext);
    URL url = findURLOfDefaultConfigurationFile(true);
    if (url != null) {
        configureByResource(url);
    } else {
        Configurator c = EnvUtil.loadFromServiceLoader(Configurator.class);
        if (c != null) {
            try {
                c.setContext(loggerContext);
                c.configure(loggerContext);
            } catch (Exception e) {
                throw new LogbackException(String.format("Failed to initialize Configurator: %s using ServiceLoader", c != null ? c.getClass()
                                .getCanonicalName() : "null"), e);
            }
        } else {
            BasicConfigurator basicConfigurator = new BasicConfigurator();
            basicConfigurator.setContext(loggerContext);
            basicConfigurator.configure(loggerContext);
        }
    }
}
 
Example #2
Source File: LogbackLoggerSpaceFactory.java    From sofa-common-tools with Apache License 2.0 6 votes vote down vote up
private void initialize(boolean willReInitialize) {
    AssertUtil.notNull(loggerContext);
    AssertUtil.notNull(properties);
    AssertUtil.notNull(confFile);

    for (Map.Entry entry : properties.entrySet()) {
        loggerContext.putProperty((String) entry.getKey(), (String) entry.getValue());
    }

    if (confFile != null && !willReInitialize) {
        try {
            new ContextInitializer(loggerContext).configureByResource(confFile);
        } catch (JoranException e) {
            throw new IllegalStateException("Logback loggerSpaceFactory build error", e);
        }
    } else {
        BasicConfigurator basicConfigurator = new BasicConfigurator();
        basicConfigurator.setContext(loggerContext);
        basicConfigurator.configure(loggerContext);
    }
}
 
Example #3
Source File: LogbackConfigurator.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void configure(LoggerContext loggerContext) {
    printInfo("Setting up CUBA default logging configuration");

    try {
        URL url = findURLOfConfigurationFile(true);
        if (url != null) {
            configureByResource(url);
        } else {
            printInfo("Configuring console output with WARN threshold");
            BasicConfigurator basicConfigurator = new BasicConfigurator();
            basicConfigurator.setContext(loggerContext);
            basicConfigurator.configure(loggerContext);
            Logger rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
            rootLogger.setLevel(Level.WARN);
        }
    } catch (Exception e) {
        printError("Failed to configure CUBA default logging: " + e);
    }
}
 
Example #4
Source File: Log.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
public static void start() {
	LOG_FILE_PATH = System.getProperty("user.dir");//System.getProperty("java.io.tmpdir");
	if(!LOG_FILE_PATH.endsWith(File.separator)) {
		LOG_FILE_PATH+=File.separator;
	}
		
	System.out.println("log dir="+LOG_FILE_PATH);

	crashReportCheck();
	deleteOldLog();
	
	logger = LoggerFactory.getLogger(RobotOverlord.class);
	BasicConfigurator.configureDefaultContext();
	
	write(PROGRAM_START_STRING);
	write("OS="+System.getProperty("os.name").toLowerCase());
}
 
Example #5
Source File: AppMain.java    From chassis with Apache License 2.0 5 votes vote down vote up
private static void initializeLogging(Arguments arguments) {
    //bootstrap depends on logback for logging console output. if the clientApplication does not want logback, they
    //need to exclude logback from their project dependencies and initialize their own logging
    try {
        AppMain.class.getClassLoader().loadClass("ch.qos.logback.classic.LoggerContext");
    } catch (ClassNotFoundException e) {
        System.err.println("No Logback found in classpath. Skipping logging initialization. This is expected if you are configuring the logging system yourself. If you are not configuring logging yourself and would like to use logging provided by java-bootstrap, ensure that the Logback dependency jar exists in your classpath.");
        return;
    }

    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    context.reset();
    BasicConfigurator.configure(context);
    ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);

    Level level = Level.valueOf(arguments.logLevel.name().toUpperCase());
    logger.setLevel(level);

    logger.info("Initialized logging at {} level", level);
}
 
Example #6
Source File: LogConfigurator.java    From gocd with Apache License 2.0 4 votes vote down vote up
protected void configureDefaultLogging() {
    ((LoggerContext) loggerFactory).reset();
    // reset will cause log level to be set to debug, so we set it to something more useful
    LogHelper.rootLogger().setLevel(Level.INFO);
    new BasicConfigurator().configure((LoggerContext) loggerFactory);
}