Search in sources :

Example 11 with LogContext

use of org.jboss.logmanager.LogContext in project wildfly-core by wildfly.

the class BootableJar method configureLogging.

private void configureLogging() throws IOException {
    if (!arguments.isVersion()) {
        // Load the boot configuration properties
        loadBootConfigProperties();
        LogContext ctx = configureLogContext();
        // Use our own LogContextSelector which returns the configured context.
        LogContext.setLogContextSelector(() -> ctx);
        // Make sure our original stdio is properly captured.
        try {
            Class.forName(org.jboss.logmanager.handlers.ConsoleHandler.class.getName(), true, org.jboss.logmanager.handlers.ConsoleHandler.class.getClassLoader());
        } catch (Throwable ignored) {
        }
        // Install JBoss Stdio to avoid any nasty crosstalk, after command line arguments are processed.
        StdioContext.install();
        final StdioContext context = StdioContext.create(new NullInputStream(), new LoggingOutputStream(org.jboss.logmanager.Logger.getLogger("stdout"), org.jboss.logmanager.Level.INFO), new LoggingOutputStream(org.jboss.logmanager.Logger.getLogger("stderr"), org.jboss.logmanager.Level.ERROR));
        StdioContext.setStdioContextSelector(new SimpleStdioContextSelector(context));
    }
}
Also used : SimpleStdioContextSelector(org.jboss.stdio.SimpleStdioContextSelector) LoggingOutputStream(org.jboss.stdio.LoggingOutputStream) LogContext(org.jboss.logmanager.LogContext) StdioContext(org.jboss.stdio.StdioContext) NullInputStream(org.jboss.stdio.NullInputStream)

Example 12 with LogContext

use of org.jboss.logmanager.LogContext in project quarkus by quarkusio.

the class LogController method getLoggers.

public static Json.JsonArrayBuilder getLoggers() {
    LogContext logContext = LogContext.getLogContext();
    TreeMap<String, Json.JsonObjectBuilder> loggerMap = new TreeMap<>();
    Enumeration<String> loggerNames = logContext.getLoggerNames();
    while (loggerNames.hasMoreElements()) {
        String loggerName = loggerNames.nextElement();
        Json.JsonObjectBuilder jsonObject = getLogger(loggerName);
        if (jsonObject != null) {
            loggerMap.put(loggerName, jsonObject);
        }
    }
    List<Json.JsonObjectBuilder> orderedLoggers = new ArrayList<>(loggerMap.values());
    Json.JsonArrayBuilder jsonArray = Json.array();
    jsonArray.addAll(orderedLoggers);
    return jsonArray;
}
Also used : ArrayList(java.util.ArrayList) LogContext(org.jboss.logmanager.LogContext) Json(io.quarkus.vertx.http.runtime.devmode.Json) TreeMap(java.util.TreeMap)

Example 13 with LogContext

use of org.jboss.logmanager.LogContext in project quarkus by quarkusio.

the class LogController method getLogger.

public static Json.JsonObjectBuilder getLogger(String loggerName) {
    LogContext logContext = LogContext.getLogContext();
    if (loggerName != null && !loggerName.isEmpty()) {
        Logger logger = logContext.getLogger(loggerName);
        Json.JsonObjectBuilder jsonObject = Json.object();
        jsonObject.put("name", loggerName);
        jsonObject.put("effectiveLevel", getEffectiveLogLevel(logger));
        jsonObject.put("configuredLevel", getConfiguredLogLevel(logger));
        return jsonObject;
    }
    return null;
}
Also used : LogContext(org.jboss.logmanager.LogContext) Json(io.quarkus.vertx.http.runtime.devmode.Json) Logger(org.jboss.logmanager.Logger)

Example 14 with LogContext

use of org.jboss.logmanager.LogContext in project quarkus by quarkusio.

the class LoggingSetupRecorder method initializeBuildTimeLogging.

public static void initializeBuildTimeLogging(LogConfig config, LogBuildTimeConfig buildConfig, ConsoleRuntimeConfig consoleConfig, LaunchMode launchMode) {
    final Map<String, CategoryConfig> categories = config.categories;
    final LogContext logContext = LogContext.getLogContext();
    final Logger rootLogger = logContext.getLogger("");
    rootLogger.setLevel(config.level);
    ErrorManager errorManager = new OnlyOnceErrorManager();
    final Map<String, CleanupFilterConfig> filters = config.filters;
    List<LogCleanupFilterElement> filterElements = new ArrayList<>(filters.size());
    for (Entry<String, CleanupFilterConfig> entry : filters.entrySet()) {
        filterElements.add(new LogCleanupFilterElement(entry.getKey(), entry.getValue().targetLevel, entry.getValue().ifStartsWith));
    }
    LogCleanupFilter logCleanupFilter = new LogCleanupFilter(filterElements);
    final ArrayList<Handler> handlers = new ArrayList<>(3);
    if (config.console.enable) {
        final Handler consoleHandler = configureConsoleHandler(config.console, consoleConfig, errorManager, logCleanupFilter, Collections.emptyList(), new RuntimeValue<>(Optional.empty()), launchMode);
        errorManager = consoleHandler.getErrorManager();
        handlers.add(consoleHandler);
    }
    Map<String, Handler> namedHandlers = createNamedHandlers(config, consoleConfig, Collections.emptyList(), errorManager, logCleanupFilter, launchMode);
    for (Map.Entry<String, CategoryConfig> entry : categories.entrySet()) {
        final String categoryName = entry.getKey();
        final Level logLevel = getLogLevel(categoryName, categories, CategoryConfig::getLevel, buildConfig.minLevel);
        final Level minLogLevel = getLogLevel(categoryName, buildConfig.categories, CategoryBuildTimeConfig::getMinLevel, buildConfig.minLevel);
        if (logLevel.intValue() < minLogLevel.intValue()) {
            log.warnf("Log level %s for category '%s' set below minimum logging level %s, promoting it to %s", logLevel, entry.getKey(), minLogLevel, minLogLevel);
            entry.getValue().level = InheritableLevel.of(minLogLevel.toString());
        }
    }
    for (Map.Entry<String, CategoryConfig> entry : categories.entrySet()) {
        final String name = entry.getKey();
        final Logger categoryLogger = logContext.getLogger(name);
        final CategoryConfig categoryConfig = entry.getValue();
        if (!categoryConfig.level.isInherited()) {
            categoryLogger.setLevel(categoryConfig.level.getLevel());
        }
        categoryLogger.setUseParentHandlers(categoryConfig.useParentHandlers);
        if (categoryConfig.handlers.isPresent()) {
            addNamedHandlersToCategory(categoryConfig, namedHandlers, categoryLogger, errorManager);
        }
    }
    InitialConfigurator.DELAYED_HANDLER.setAutoFlush(false);
    InitialConfigurator.DELAYED_HANDLER.setBuildTimeHandlers(handlers.toArray(EmbeddedConfigurator.NO_HANDLERS));
}
Also used : OnlyOnceErrorManager(org.jboss.logmanager.errormanager.OnlyOnceErrorManager) ErrorManager(java.util.logging.ErrorManager) ArrayList(java.util.ArrayList) LogContext(org.jboss.logmanager.LogContext) SyslogHandler(org.jboss.logmanager.handlers.SyslogHandler) FileHandler(org.jboss.logmanager.handlers.FileHandler) PeriodicSizeRotatingFileHandler(org.jboss.logmanager.handlers.PeriodicSizeRotatingFileHandler) ConsoleHandler(org.jboss.logmanager.handlers.ConsoleHandler) SizeRotatingFileHandler(org.jboss.logmanager.handlers.SizeRotatingFileHandler) Handler(java.util.logging.Handler) AsyncHandler(org.jboss.logmanager.handlers.AsyncHandler) Logger(org.jboss.logmanager.Logger) OnlyOnceErrorManager(org.jboss.logmanager.errormanager.OnlyOnceErrorManager) Level(java.util.logging.Level) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with LogContext

use of org.jboss.logmanager.LogContext in project kafka-admin-api by bf2fc6cc711aee1a0c2a.

the class LoggingConfigWatcher method delete.

private void delete() {
    LogContext context = LogContext.getLogContext();
    overriddenLoggers.forEach((category, originalLevel) -> {
        org.jboss.logmanager.Logger logger = context.getLogger(category);
        LOGGER.infof("Restoring original log level for logger %s: %s", category.isEmpty() ? "ROOT" : category, originalLevel);
        if (originalLevel instanceof Inherit) {
            originalLevel = null;
        }
        logger.setLevel(originalLevel);
    });
    overriddenLoggers.clear();
}
Also used : LogContext(org.jboss.logmanager.LogContext)

Aggregations

LogContext (org.jboss.logmanager.LogContext)33 ModelNode (org.jboss.dmr.ModelNode)7 PathAddress (org.jboss.as.controller.PathAddress)6 ConfigurationPersistence (org.jboss.as.logging.logmanager.ConfigurationPersistence)6 Logger (org.jboss.logmanager.Logger)6 ArrayList (java.util.ArrayList)5 Level (java.util.logging.Level)5 PropertyConfigurator (org.jboss.logmanager.PropertyConfigurator)5 File (java.io.File)4 InputStream (java.io.InputStream)4 LogContextConfiguration (org.jboss.logmanager.config.LogContextConfiguration)4 StdioContext (org.jboss.stdio.StdioContext)4 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Properties (java.util.Properties)3 Handler (java.util.logging.Handler)3 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)3 Configurator (org.jboss.logmanager.Configurator)3