Search in sources :

Example 31 with LogContext

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

the class LogController method updateLogLevel.

public static void updateLogLevel(String loggerName, String levelValue) {
    LogContext logContext = LogContext.getLogContext();
    Logger logger = logContext.getLogger(loggerName);
    java.util.logging.Level level;
    if (levelValue == null || levelValue.isBlank()) {
        if (logger.getParent() != null) {
            level = logger.getParent().getLevel();
        } else {
            throw new IllegalArgumentException("The level of the root logger cannot be set to null");
        }
    } else {
        level = Level.parse(levelValue);
    }
    logger.setLevel(level);
    LOG.info("Log level updated [" + loggerName + "] changed to [" + levelValue + "]");
}
Also used : LogContext(org.jboss.logmanager.LogContext) Logger(org.jboss.logmanager.Logger) Level(java.util.logging.Level)

Example 32 with LogContext

use of org.jboss.logmanager.LogContext in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class LoggingConfigWatcherTest method testConfigParsing.

@Test
public void testConfigParsing() throws MalformedURLException, IOException {
    LoggingConfigWatcher.updateLoggingConfig(LoggingConfigWatcher.class.getResource("/loggingconfig/application.properties"));
    LogContext logContext = LogContext.getLogContext();
    org.jboss.logmanager.Logger logger = logContext.getLogger("some.category");
    assertEquals(Level.DEBUG, logger.getLevel());
    logger = logContext.getLogger("some.other.category");
    assertEquals(Level.WARNING, logger.getLevel());
}
Also used : LogContext(org.jboss.logmanager.LogContext) Test(org.junit.jupiter.api.Test)

Example 33 with LogContext

use of org.jboss.logmanager.LogContext in project activemq-artemis by rh-messaging.

the class LoggingConfigurationFileReloader method getOrCreateUpdater.

private LoggingConfigurationUpdater getOrCreateUpdater() {
    final LogContext logContext = LogContext.getLogContext();
    final org.jboss.logmanager.Logger rootLogger = logContext.getLogger("");
    LoggingConfigurationUpdater updater = rootLogger.getAttachment(KEY);
    if (updater == null) {
        final LogContextConfiguration logContextConfiguration = getOrCreateConfiguration(rootLogger);
        if (logContextConfiguration == null) {
            return null;
        }
        updater = new LoggingConfigurationUpdater(logContextConfiguration);
        final LoggingConfigurationUpdater appearing = rootLogger.attachIfAbsent(KEY, updater);
        if (appearing != null) {
            updater = appearing;
        }
    }
    return updater;
}
Also used : LogContextConfiguration(org.jboss.logmanager.config.LogContextConfiguration) 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