use of org.apache.logging.log4j.core.config.LoggerConfig in project geode by apache.
the class AlertAppender method removeAlertListener.
public synchronized boolean removeAlertListener(final DistributedMember member) {
final boolean memberWasFound = this.listeners.remove(new Listener(null, member));
if (memberWasFound) {
if (this.listeners.size() == 0) {
this.appenderContext.getLoggerContext().removePropertyChangeListener(this);
this.appenderContext.getLoggerConfig().removeAppender(APPENDER_NAME);
} else {
LoggerConfig loggerConfig = this.appenderContext.getLoggerConfig();
loggerConfig.addAppender(this, this.listeners.get(0).getLevel(), null);
}
if (logger.isDebugEnabled()) {
logger.debug("Removed alert listener for member {}", member);
}
}
return memberWasFound;
}
use of org.apache.logging.log4j.core.config.LoggerConfig 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);
}
use of org.apache.logging.log4j.core.config.LoggerConfig in project geode by apache.
the class AlertAppenderJUnitTest method testAppenderToConfigHandling.
/**
* Verifies that the appender is correctly added and removed from the Log4j configuration and that
* when the configuration is changed the appender is still there.
*/
@Test
public void testAppenderToConfigHandling() throws Exception {
LogService.setBaseLogLevel(Level.WARN);
final String appenderName = AlertAppender.getInstance().getName();
final AppenderContext appenderContext = LogService.getAppenderContext();
LoggerConfig loggerConfig = appenderContext.getLoggerConfig();
// Find out home many appenders exist before we get started
final int startingSize = loggerConfig.getAppenders().size();
// Add a listener and verify that the appender was added to log4j
DistributedMember member1 = createTestDistributedMember("Member1");
AlertAppender.getInstance().addAlertListener(member1, Alert.SEVERE);
assertEquals(loggerConfig.getAppenders().values().toString(), startingSize + 1, loggerConfig.getAppenders().size());
assertTrue(loggerConfig.getAppenders().containsKey(appenderName));
// Add another listener and verify that there's still only 1 alert appender
DistributedMember member2 = createTestDistributedMember("Member1");
AlertAppender.getInstance().addAlertListener(member2, Alert.SEVERE);
assertEquals(startingSize + 1, loggerConfig.getAppenders().size());
// Modify the config and verify that the appender still exists
assertEquals(Level.WARN, LogService.getLogger(LogService.BASE_LOGGER_NAME).getLevel());
LogService.setBaseLogLevel(Level.INFO);
assertEquals(Level.INFO, LogService.getLogger(LogService.BASE_LOGGER_NAME).getLevel());
loggerConfig = appenderContext.getLoggerConfig();
assertEquals(startingSize + 1, loggerConfig.getAppenders().size());
assertTrue(loggerConfig.getAppenders().containsKey(appenderName));
// Remove the listeners and verify that the appender was removed from log4j
assertTrue(AlertAppender.getInstance().removeAlertListener(member2));
assertFalse(AlertAppender.getInstance().removeAlertListener(member1));
assertEquals(startingSize, loggerConfig.getAppenders().size());
assertFalse(loggerConfig.getAppenders().containsKey(appenderName));
}
use of org.apache.logging.log4j.core.config.LoggerConfig in project logging-log4j2 by apache.
the class Logger method getParent.
/**
* This method is only used for 1.x compatibility. Returns the parent of this Logger. If it doesn't already exist
* return a temporary Logger.
*
* @return The parent Logger.
*/
public Logger getParent() {
final LoggerConfig lc = privateConfig.loggerConfig.getName().equals(getName()) ? privateConfig.loggerConfig.getParent() : privateConfig.loggerConfig;
if (lc == null) {
return null;
}
final String lcName = lc.getName();
final MessageFactory messageFactory = getMessageFactory();
if (context.hasLogger(lcName, messageFactory)) {
return context.getLogger(lcName, messageFactory);
}
return new Logger(context, lcName, messageFactory);
}
use of org.apache.logging.log4j.core.config.LoggerConfig in project logging-log4j2 by apache.
the class Log4j1ConfigurationFactoryTest method testConsole.
private Layout<?> testConsole(final String configResource) throws Exception {
final Configuration configuration = getConfiguration(configResource);
final String name = "Console";
final ConsoleAppender appender = configuration.getAppender(name);
assertNotNull("Missing appender '" + name + "' in configuration " + configResource + " → " + configuration, appender);
assertEquals(Target.SYSTEM_ERR, appender.getTarget());
//
final LoggerConfig loggerConfig = configuration.getLoggerConfig("com.example.foo");
assertNotNull(loggerConfig);
assertEquals(Level.DEBUG, loggerConfig.getLevel());
configuration.start();
configuration.stop();
return appender.getLayout();
}
Aggregations