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;
}
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());
}
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);
}
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();
}
}
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);
}
Aggregations