@Test public void testNewInstanceReturnsAsyncLogger() { final Logger logger = new AsyncLoggerContext("a").newInstance( new LoggerContext("a"), "a", null); assertTrue(logger instanceof AsyncLogger); CoreLoggerContexts.stopLoggerContext(); // stop async thread } }
RingBufferAdmin ring; if (loggerContext instanceof AsyncLoggerContext) { ring = ((AsyncLoggerContext) loggerContext).createRingBufferAdmin(); } else { ring = ((AsyncLoggerConfig) ((org.apache.logging.log4j.core.Logger) log).get()).createRingBufferAdmin("");
@Override protected LoggerContext createContext(final String name, final URI configLocation) { return new AsyncLoggerContext(name, null, configLocation); }
/** * Creates and returns a new {@code RingBufferAdmin} that instruments the ringbuffer of the {@code AsyncLogger} * objects in this {@code LoggerContext}. * * @return a new {@code RingBufferAdmin} that instruments the ringbuffer */ public RingBufferAdmin createRingBufferAdmin() { return loggerDisruptor.createRingBufferAdmin(getName()); }
@Override public synchronized void start() { if (this.isStopped() || this.isStopping()) { throw new IllegalStateException("Cannot start this Log4jWebInitializerImpl after it was stopped."); } // only do this once if (this.isInitialized()) { super.setStarting(); this.name = this.substitutor.replace(this.servletContext.getInitParameter(LOG4J_CONTEXT_NAME)); final String location = this.substitutor.replace(this.servletContext .getInitParameter(LOG4J_CONFIG_LOCATION)); final boolean isJndi = "true".equalsIgnoreCase(this.servletContext .getInitParameter(IS_LOG4J_CONTEXT_SELECTOR_NAMED)); if (isJndi) { this.initializeJndi(location); } else { this.initializeNonJndi(location); } if (this.loggerContext instanceof AsyncLoggerContext) { ((AsyncLoggerContext) this.loggerContext).setUseThreadLocals(false); } this.servletContext.setAttribute(CONTEXT_ATTRIBUTE, this.loggerContext); super.setStarted(); } }
@Override public void start(final Configuration config) { maybeStartHelper(config); super.start(config); }
@Override public boolean stop(final long timeout, final TimeUnit timeUnit) { setStopping(); // first stop Disruptor loggerDisruptor.stop(timeout, timeUnit); super.stop(timeout, timeUnit); return true; }
this.context = new AsyncLoggerContext(name);
private void maybeStartHelper(final Configuration config) { // If no log4j configuration was found, there are no loggers // and there is no point in starting the disruptor (which takes up // significant memory and starts a thread). if (config instanceof DefaultConfiguration) { StatusLogger.getLogger().debug("[{}] Not starting Disruptor for DefaultConfiguration.", getName()); } else { loggerDisruptor.start(); } }
m_log4jContext.stop(); if (async) { m_log4jContext = new AsyncLoggerContext(LOGGER_CONTEXT_NAME); } else { m_log4jContext = new LoggerContext(LOGGER_CONTEXT_NAME);
final RingBufferAdmin rbmbean = ((AsyncLoggerContext) ctx).createRingBufferAdmin(); if (rbmbean.getBufferSize() > 0) {