@Test public void testIncludeLocationDefaultsToFalse() { final LoggerConfig rootLoggerConfig = AsyncLoggerConfig.RootLogger.createLogger( null, "INFO", null, new AppenderRef[0], null, new DefaultConfiguration(), null); assertFalse("Include location should default to false for async logggers", rootLoggerConfig.isIncludeLocation()); final LoggerConfig loggerConfig = AsyncLoggerConfig.createLogger( null, "INFO", "com.foo.Bar", null, new AppenderRef[0], null, new DefaultConfiguration(), null); assertFalse("Include location should default to false for async logggers", loggerConfig.isIncludeLocation()); } }
ring = ((AsyncLoggerContext) loggerContext).createRingBufferAdmin(); } else { ring = ((AsyncLoggerConfig) ((org.apache.logging.log4j.core.Logger) log).get()).createRingBufferAdmin("");
((AsyncLoggerConfig)((org.apache.logging.log4j.core.Logger) log).get()).callAppenders(event); for (int j = 0; j < 3000; j++) { map.remove(String.valueOf(j));
@Override public boolean stop(final long timeout, final TimeUnit timeUnit) { setStopping(); super.stop(timeout, timeUnit, false); LOGGER.trace("AsyncLoggerConfig[{}] stopping...", displayName()); setStopped(); return true; }
@PluginFactory public static LoggerConfig createLogger( @PluginAttribute("additivity") final String additivity, @PluginAttribute("level") final String levelName, @PluginAttribute("includeLocation") final String includeLocation, @PluginElement("AppenderRef") final AppenderRef[] refs, @PluginElement("Properties") final Property[] properties, @PluginConfiguration final Configuration config, @PluginElement("Filter") final Filter filter) { final List<AppenderRef> appenderRefs = Arrays.asList(refs); Level level; try { level = Level.toLevel(levelName, Level.ERROR); } catch (final Exception ex) { LOGGER.error( "Invalid Log level specified: {}. Defaulting to Error", levelName); level = Level.ERROR; } final boolean additive = Booleans.parseBoolean(additivity, true); return new AsyncLoggerConfig(LogManager.ROOT_LOGGER_NAME, appenderRefs, filter, level, additive, properties, config, AsyncLoggerConfig.includeLocation(includeLocation)); } }
@Override public void logMessage(final AsyncLoggerConfig asyncLoggerConfig, final LogEvent event) { asyncLoggerConfig.callAppendersInBackgroundThread(event); }
@Override public void logMessage(final AsyncLoggerConfig asyncLoggerConfig, final LogEvent event) { asyncLoggerConfig.callAppendersInCurrentThread(event); }
@Override public void start() { LOGGER.trace("AsyncLoggerConfig[{}] starting...", displayName()); super.start(); }
protected AsyncLoggerConfig(final String name, final List<AppenderRef> appenders, final Filter filter, final Level level, final boolean additive, final Property[] properties, final Configuration config, final boolean includeLocation) { super(name, appenders, filter, level, additive, properties, config, includeLocation); delegate = config.getAsyncLoggerConfigDelegate(); delegate.setLogEventFactory(getLogEventFactory()); }
@Override public void onEvent(final Log4jEventWrapper event, final long sequence, final boolean endOfBatch) throws Exception { event.event.setEndOfBatch(endOfBatch); event.loggerConfig.asyncCallAppenders(event.event); event.clear(); notifyIntermediateProgress(sequence); }
final boolean additive = Booleans.parseBoolean(additivity, true); return new AsyncLoggerConfig(name, appenderRefs, filter, level, additive, properties, config, includeLocation(includeLocation));
/** * Creates and returns a new {@code RingBufferAdmin} that instruments the * ringbuffer of this {@code AsyncLoggerConfig}. * * @param contextName name of the {@code LoggerContext} * @return a new {@code RingBufferAdmin} that instruments the ringbuffer */ public RingBufferAdmin createRingBufferAdmin(final String contextName) { return delegate.createRingBufferAdmin(contextName, getName()); }
@Before public void before() { context = getDefaultContext(); testAppender = new TestAppender(TEST_APPENDER, null, null); context.getConfiguration().addAppender(testAppender); LoggerConfig loggerConfig = AsyncLoggerConfig.createLogger("false", LEVEL.name(), CATEGORY, "true", new AppenderRef[] {AppenderRef.createAppenderRef(TEST_APPENDER, null, null)}, null, context.getConfiguration(), null); loggerConfig.addAppender(testAppender, null, null); context.getConfiguration().addLogger(CATEGORY, loggerConfig); context.getConfiguration().start(); context.updateLoggers(); }
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()); } } }