Search in sources :

Example 96 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext in project geode by apache.

the class Configurator method getOrCreateLoggerConfig.

public static LoggerConfig getOrCreateLoggerConfig(String name) {
    LoggerContext context = (LoggerContext) LogManager.getContext(false);
    Configuration config = context.getConfiguration();
    LoggerConfig logConfig = config.getLoggerConfig(name);
    boolean update = false;
    if (!logConfig.getName().equals(name)) {
        List<AppenderRef> appenderRefs = logConfig.getAppenderRefs();
        Map<Property, Boolean> properties = logConfig.getProperties();
        Set<Property> props = properties == null ? null : properties.keySet();
        logConfig = LoggerConfig.createLogger(String.valueOf(logConfig.isAdditive()), logConfig.getLevel(), name, String.valueOf(logConfig.isIncludeLocation()), appenderRefs == null ? null : appenderRefs.toArray(new AppenderRef[appenderRefs.size()]), props == null ? null : props.toArray(new Property[props.size()]), config, null);
        config.addLogger(name, logConfig);
        update = true;
    }
    if (update) {
        context.updateLoggers();
    }
    return logConfig;
}
Also used : Configuration(org.apache.logging.log4j.core.config.Configuration) AppenderRef(org.apache.logging.log4j.core.config.AppenderRef) LoggerContext(org.apache.logging.log4j.core.LoggerContext) Property(org.apache.logging.log4j.core.config.Property) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Example 97 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext in project geode by apache.

the class AppenderContext method getLoggerConfig.

public LoggerConfig getLoggerConfig() {
    final Logger logger = getLogger();
    final LoggerContext context = logger.getContext();
    return context.getConfiguration().getLoggerConfig(logger.getName());
}
Also used : Logger(org.apache.logging.log4j.core.Logger) LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Example 98 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext in project geode by apache.

the class LogService method init.

private static void init() {
    LoggerContext context = ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(BASE_LOGGER_NAME, GemFireParameterizedMessageFactory.INSTANCE)).getContext();
    context.removePropertyChangeListener(propertyChangeListener);
    context.addPropertyChangeListener(propertyChangeListener);
    // propertyChangeListener invokes configureFastLoggerDelegating
    context.reconfigure();
    configureLoggers(false, false);
}
Also used : Logger(org.apache.logging.log4j.Logger) StatusLogger(org.apache.logging.log4j.status.StatusLogger) LogWriterLogger(org.apache.geode.internal.logging.log4j.LogWriterLogger) FastLogger(org.apache.geode.internal.logging.log4j.FastLogger) LoggerContext(org.apache.logging.log4j.core.LoggerContext)

Example 99 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext in project geode by apache.

the class GfshInitFileJUnitTest method tearDownAfterClass.

/*
   * Restore logging to state prior to the execution of this class
   */
@AfterClass
public static void tearDownAfterClass() throws Exception {
    for (Handler handler : saveHandlers) {
        julLogger.addHandler(handler);
    }
    if (saveLog4j2Config == null) {
        System.clearProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
    } else {
        System.setProperty(ConfigurationFactory.CONFIGURATION_FILE_PROPERTY, saveLog4j2Config);
        ((LoggerContext) LogManager.getContext(false)).reconfigure();
    }
}
Also used : Handler(java.util.logging.Handler) LoggerContext(org.apache.logging.log4j.core.LoggerContext) AfterClass(org.junit.AfterClass)

Example 100 with LoggerContext

use of org.apache.logging.log4j.core.LoggerContext in project geode by apache.

the class DUnitLauncher method addSuspectFileAppender.

/**
   * Add an appender to Log4j which sends all INFO+ messages to a separate file which will be used
   * later to scan for suspect strings. The pattern of the messages conforms to the original log
   * format so that hydra will be able to parse them.
   */
private static void addSuspectFileAppender(final String workspaceDir) {
    final String suspectFilename = new File(workspaceDir, SUSPECT_FILENAME).getAbsolutePath();
    final LoggerContext appenderContext = ((org.apache.logging.log4j.core.Logger) LogManager.getLogger(LogService.BASE_LOGGER_NAME)).getContext();
    final PatternLayout layout = PatternLayout.createLayout("[%level{lowerCase=true} %date{yyyy/MM/dd HH:mm:ss.SSS z} <%thread> tid=%tid] %message%n%throwable%n", null, null, null, Charset.defaultCharset(), true, false, "", "");
    final FileAppender fileAppender = FileAppender.createAppender(suspectFilename, "true", "false", DUnitLauncher.class.getName(), "true", "false", "false", "0", layout, null, null, null, appenderContext.getConfiguration());
    fileAppender.start();
    LoggerConfig loggerConfig = appenderContext.getConfiguration().getLoggerConfig(LogService.BASE_LOGGER_NAME);
    loggerConfig.addAppender(fileAppender, Level.INFO, null);
}
Also used : FileAppender(org.apache.logging.log4j.core.appender.FileAppender) PatternLayout(org.apache.logging.log4j.core.layout.PatternLayout) File(java.io.File) LoggerContext(org.apache.logging.log4j.core.LoggerContext) LoggerConfig(org.apache.logging.log4j.core.config.LoggerConfig)

Aggregations

LoggerContext (org.apache.logging.log4j.core.LoggerContext)156 Configuration (org.apache.logging.log4j.core.config.Configuration)53 Test (org.junit.Test)33 LoggerConfig (org.apache.logging.log4j.core.config.LoggerConfig)32 Appender (org.apache.logging.log4j.core.Appender)15 File (java.io.File)12 IOException (java.io.IOException)11 Logger (org.apache.logging.log4j.Logger)11 BeforeClass (org.junit.BeforeClass)11 Map (java.util.Map)9 Level (org.apache.logging.log4j.Level)8 LogEvent (org.apache.logging.log4j.core.LogEvent)8 Log4jLogEvent (org.apache.logging.log4j.core.impl.Log4jLogEvent)7 SimpleMessage (org.apache.logging.log4j.message.SimpleMessage)7 Logger (org.apache.logging.log4j.core.Logger)6 AbstractConfiguration (org.apache.logging.log4j.core.config.AbstractConfiguration)5 AppenderRef (org.apache.logging.log4j.core.config.AppenderRef)5 PatternLayout (org.apache.logging.log4j.core.layout.PatternLayout)5 FileAppender (org.apache.logging.log4j.core.appender.FileAppender)4 BuiltConfiguration (org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration)4