use of org.apache.logging.log4j.core.config.LoggerConfig in project logging-log4j2 by apache.
the class LoggerUpdateTest method resetLevel.
@Test
public void resetLevel() {
final org.apache.logging.log4j.Logger logger = context.getLogger("com.apache.test");
logger.traceEntry();
List<LogEvent> events = app.getEvents();
assertEquals("Incorrect number of events. Expected 1, actual " + events.size(), 1, events.size());
app.clear();
final LoggerContext ctx = LoggerContext.getContext(false);
final Configuration config = ctx.getConfiguration();
final LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
/* You could also specify the actual logger name as below and it will return the LoggerConfig used by the Logger.
LoggerConfig loggerConfig = getLoggerConfig("com.apache.test");
*/
loggerConfig.setLevel(Level.DEBUG);
// This causes all Loggers to refetch information from their LoggerConfig.
ctx.updateLoggers();
logger.traceEntry();
events = app.getEvents();
assertEquals("Incorrect number of events. Expected 0, actual " + events.size(), 0, events.size());
}
use of org.apache.logging.log4j.core.config.LoggerConfig in project logging-log4j2 by apache.
the class ConfigurationTestUtils method updateLoggers.
static void updateLoggers(final Appender appender, final Configuration config) {
final Level level = null;
final Filter filter = null;
for (final LoggerConfig loggerConfig : config.getLoggers().values()) {
loggerConfig.addAppender(appender, level, filter);
}
config.getRootLogger().addAppender(appender, level, filter);
}
use of org.apache.logging.log4j.core.config.LoggerConfig in project logging-log4j2 by apache.
the class PropertiesConfigurationRootLoggerOnlyTest method testPropertiesConfiguration.
@Test
public void testPropertiesConfiguration() {
final Configuration config = context.getConfiguration();
assertNotNull("No configuration created", config);
assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1);
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 1);
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
use of org.apache.logging.log4j.core.config.LoggerConfig in project logging-log4j2 by apache.
the class Server method registerLoggerConfigs.
private static void registerLoggerConfigs(final LoggerContext ctx, final MBeanServer mbs, final Executor executor) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
final Map<String, LoggerConfig> map = ctx.getConfiguration().getLoggers();
for (final String name : map.keySet()) {
final LoggerConfig cfg = map.get(name);
final LoggerConfigAdmin mbean = new LoggerConfigAdmin(ctx, cfg);
register(mbs, mbean, mbean.getObjectName());
if (cfg instanceof AsyncLoggerConfig) {
final AsyncLoggerConfig async = (AsyncLoggerConfig) cfg;
final RingBufferAdmin rbmbean = async.createRingBufferAdmin(ctx.getName());
register(mbs, rbmbean, rbmbean.getObjectName());
}
}
}
use of org.apache.logging.log4j.core.config.LoggerConfig in project logging-log4j2 by apache.
the class AbstractStringLayout method serializeToString.
protected String serializeToString(final Serializer serializer) {
if (serializer == null) {
return null;
}
final LoggerConfig rootLogger = getConfiguration().getRootLogger();
// Using "" for the FQCN, does it matter?
final LogEvent logEvent = getLogEventFactory().createEvent(rootLogger.getName(), null, Strings.EMPTY, rootLogger.getLevel(), null, null, null);
return serializer.toSerializable(logEvent);
}
Aggregations