org.jboss.logmanager.Configurator Java Examples

The following examples show how to use org.jboss.logmanager.Configurator. 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: ConfigurationPersistence.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Gets the property configurator. If the {@link ConfigurationPersistence} does not exist a new one is created.
 *
 * @param logContext the log context used to find the property configurator or to attach it to.
 *
 * @return the property configurator
 */
public static ConfigurationPersistence getOrCreateConfigurationPersistence(final LogContext logContext) {
    final Logger root = logContext.getLogger(CommonAttributes.ROOT_LOGGER_NAME);
    final ConfigurationPersistence result;
    synchronized (LOCK) {
        Configurator configurator = root.getAttachment(Configurator.ATTACHMENT_KEY);
        if (configurator == null) {
            configurator = new ConfigurationPersistence(logContext);
            Configurator existing = root.attachIfAbsent(Configurator.ATTACHMENT_KEY, configurator);
            if (existing != null) {
                configurator = existing;
            }
        }
        if (configurator instanceof ConfigurationPersistence) {
            // We have the correct configurator
            result = (ConfigurationPersistence) configurator;
        } else if (configurator instanceof PropertyConfigurator) {
            // Create a new configurator delegating to the configurator found
            result = new ConfigurationPersistence((PropertyConfigurator) configurator);
            root.attach(Configurator.ATTACHMENT_KEY, result);
        } else {
            // An unknown configurator, log a warning and replace
            LoggingLogger.ROOT_LOGGER.replacingConfigurator(configurator);
            result = new ConfigurationPersistence(logContext);
            root.attach(Configurator.ATTACHMENT_KEY, result);
        }
    }
    return result;
}
 
Example #2
Source File: WildFlyLogContextSelector.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static void clearLogContext() {
    // Remove the configurator and clear the log context
    final Configurator configurator = EMBEDDED_LOG_CONTEXT.getLogger("").detach(Configurator.ATTACHMENT_KEY);
    // If this was a PropertyConfigurator we can use the LogContextConfiguration API to tear down the LogContext
    if (configurator instanceof PropertyConfigurator) {
        final LogContextConfiguration logContextConfiguration = ((PropertyConfigurator) configurator).getLogContextConfiguration();
        clearLogContext(logContextConfiguration);
    } else if (configurator instanceof LogContextConfiguration) {
        clearLogContext((LogContextConfiguration) configurator);
    } else {
        // Remove all the handlers and close them as well as reset the loggers
        final List<String> loggerNames = Collections.list(EMBEDDED_LOG_CONTEXT.getLoggerNames());
        for (String name : loggerNames) {
            final Logger logger = EMBEDDED_LOG_CONTEXT.getLoggerIfExists(name);
            if (logger != null) {
                final Handler[] handlers = logger.clearHandlers();
                if (handlers != null) {
                    for (Handler handler : handlers) {
                        handler.close();
                    }
                }
                logger.setFilter(null);
                logger.setUseParentFilters(false);
                logger.setUseParentHandlers(true);
                logger.setLevel(Level.INFO);
            }
        }
    }
}
 
Example #3
Source File: AbstractLoggingSubsystemTest.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SuppressWarnings("ChainOfInstanceofChecks")
private LogContextConfiguration getLogContextConfiguration(final LogContext logContext) {
    final Configurator configurator = logContext.getAttachment(CommonAttributes.ROOT_LOGGER_NAME, Configurator.ATTACHMENT_KEY);
    if (configurator instanceof LogContextConfiguration) {
        return (LogContextConfiguration) configurator;
    }
    if (configurator instanceof PropertyConfigurator) {
        return ((PropertyConfigurator) configurator).getLogContextConfiguration();
    }
    return null;
}
 
Example #4
Source File: EmbeddedLogContext.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Attempts to clear the global log context used for embedded servers.
 */
static synchronized void clearLogContext() {
    final LogContext embeddedLogContext = Holder.LOG_CONTEXT;
    // Remove the configurator and clear the log context
    final Configurator configurator = embeddedLogContext.getLogger("").detach(Configurator.ATTACHMENT_KEY);
    // If this was a PropertyConfigurator we can use the LogContextConfiguration API to tear down the LogContext
    if (configurator instanceof PropertyConfigurator) {
        final LogContextConfiguration logContextConfiguration = ((PropertyConfigurator) configurator).getLogContextConfiguration();
        clearLogContext(logContextConfiguration);
    } else if (configurator instanceof LogContextConfiguration) {
        clearLogContext((LogContextConfiguration) configurator);
    } else {
        // Remove all the handlers and close them as well as reset the loggers
        final List<String> loggerNames = Collections.list(embeddedLogContext.getLoggerNames());
        for (String name : loggerNames) {
            final Logger logger = embeddedLogContext.getLoggerIfExists(name);
            if (logger != null) {
                final Handler[] handlers = logger.clearHandlers();
                if (handlers != null) {
                    for (Handler handler : handlers) {
                        handler.close();
                    }
                }
                logger.setFilter(null);
                logger.setUseParentFilters(false);
                logger.setUseParentHandlers(true);
                logger.setLevel(Level.INFO);
            }
        }
    }
}
 
Example #5
Source File: ConfigurationPersistence.java    From wildfly-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Gets the property configurator. If the {@link ConfigurationPersistence} does not exist a {@code null} is
 * returned.
 *
 * @param logContext the log context used to find the property configurator or to attach it to.
 *
 * @return the property configurator or {@code null}
 */
public static ConfigurationPersistence getConfigurationPersistence(final LogContext logContext) {
    if (logContext == null) return null;
    return (ConfigurationPersistence) logContext.getAttachment(CommonAttributes.ROOT_LOGGER_NAME, Configurator.ATTACHMENT_KEY);
}
 
Example #6
Source File: LoggingLogger.java    From wildfly-core with GNU Lesser General Public License v2.1 2 votes vote down vote up
/**
 * Logs a warning message indicating the configurator class is an unknown type and will be replaced.
 *
 * @param c the class that is being replaced
 */
@LogMessage(level = WARN)
@Message(id = 13, value = "A configurator class, '%s', is not a known configurator and will be replaced.")
void replacingConfigurator(@Transform(TransformType.GET_CLASS) Configurator c);