Search in sources :

Example 1 with LogService

use of liquibase.logging.LogService in project liquibase by liquibase.

the class LiquibaseCommandLine method configureLogging.

private void configureLogging(Level logLevel, File logFile) throws IOException {
    configuredLogLevel = logLevel;
    System.setProperty("java.util.logging.SimpleFormatter.format", "[%1$tF %1$tT] %4$s [%2$s] %5$s%6$s%n");
    java.util.logging.Logger liquibaseLogger = java.util.logging.Logger.getLogger("liquibase");
    final JavaLogService logService = (JavaLogService) Scope.getCurrentScope().get(Scope.Attr.logService, LogService.class);
    logService.setParent(liquibaseLogger);
    java.util.logging.Logger rootLogger = java.util.logging.Logger.getLogger("");
    Level cliLogLevel = logLevel;
    if (logFile != null) {
        if (fileHandler == null) {
            fileHandler = new FileHandler(logFile.getAbsolutePath(), true);
            fileHandler.setFormatter(new SimpleFormatter());
            rootLogger.addHandler(fileHandler);
        }
        fileHandler.setLevel(logLevel);
        if (logLevel == Level.OFF) {
            fileHandler.setLevel(Level.FINE);
        }
        cliLogLevel = Level.OFF;
    }
    rootLogger.setLevel(logLevel);
    liquibaseLogger.setLevel(logLevel);
    for (Handler handler : rootLogger.getHandlers()) {
        if (handler instanceof ConsoleHandler) {
            handler.setLevel(cliLogLevel);
        }
        handler.setFilter(new SecureLogFilter(logService.getFilter()));
    }
}
Also used : java.util.logging(java.util.logging) JavaLogService(liquibase.logging.core.JavaLogService) LogService(liquibase.logging.LogService) JavaLogService(liquibase.logging.core.JavaLogService)

Example 2 with LogService

use of liquibase.logging.LogService in project liquibase by liquibase.

the class Scope method getCurrentScope.

public static Scope getCurrentScope() {
    if (scopeManager == null) {
        scopeManager = new SingletonScopeManager();
    }
    if (scopeManager.getCurrentScope() == null) {
        Scope rootScope = new Scope();
        scopeManager.setCurrentScope(rootScope);
        rootScope.values.put(Attr.logService.name(), new JavaLogService());
        rootScope.values.put(Attr.resourceAccessor.name(), new ClassLoaderResourceAccessor());
        rootScope.values.put(Attr.serviceLocator.name(), new StandardServiceLocator());
        rootScope.values.put(Attr.ui.name(), new ConsoleUIService());
        rootScope.getSingleton(LiquibaseConfiguration.class).init(rootScope);
        LogService overrideLogService = rootScope.getSingleton(LogServiceFactory.class).getDefaultLogService();
        if (overrideLogService == null) {
            throw new UnexpectedLiquibaseException("Cannot find default log service");
        }
        rootScope.values.put(Attr.logService.name(), overrideLogService);
        // check for higher-priority serviceLocator
        ServiceLocator serviceLocator = rootScope.getServiceLocator();
        for (ServiceLocator possibleLocator : serviceLocator.findInstances(ServiceLocator.class)) {
            if (possibleLocator.getPriority() > serviceLocator.getPriority()) {
                serviceLocator = possibleLocator;
            }
        }
        rootScope.values.put(Attr.serviceLocator.name(), serviceLocator);
        rootScope.values.put(Attr.osgiPlatform.name(), Activator.OSGIContainerChecker.isOsgiPlatform());
    }
    return scopeManager.getCurrentScope();
}
Also used : StandardServiceLocator(liquibase.servicelocator.StandardServiceLocator) ServiceLocator(liquibase.servicelocator.ServiceLocator) ConsoleUIService(liquibase.ui.ConsoleUIService) StandardServiceLocator(liquibase.servicelocator.StandardServiceLocator) JavaLogService(liquibase.logging.core.JavaLogService) LiquibaseConfiguration(liquibase.configuration.LiquibaseConfiguration) ClassLoaderResourceAccessor(liquibase.resource.ClassLoaderResourceAccessor) LogServiceFactory(liquibase.logging.core.LogServiceFactory) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) LogService(liquibase.logging.LogService) JavaLogService(liquibase.logging.core.JavaLogService)

Aggregations

LogService (liquibase.logging.LogService)2 JavaLogService (liquibase.logging.core.JavaLogService)2 java.util.logging (java.util.logging)1 LiquibaseConfiguration (liquibase.configuration.LiquibaseConfiguration)1 UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)1 LogServiceFactory (liquibase.logging.core.LogServiceFactory)1 ClassLoaderResourceAccessor (liquibase.resource.ClassLoaderResourceAccessor)1 ServiceLocator (liquibase.servicelocator.ServiceLocator)1 StandardServiceLocator (liquibase.servicelocator.StandardServiceLocator)1 ConsoleUIService (liquibase.ui.ConsoleUIService)1