private Configuration loadConfiguration(String resourcePath) throws IOException { InputStream in = getClass().getClassLoader().getResourceAsStream(resourcePath); try { Configuration configuration = new XmlConfiguration(new LoggerContext("test"), new ConfigurationSource(in)); configuration.initialize(); configuration.start(); return configuration; } finally { in.close(); } } }
@Parameters public static Collection<Object[]> data() { return Arrays.asList(new Object[][] { { new LoggerContext("").getLogger("", null) }, { LogManager.getRootLogger() }, { LogManager.getLogger() }, { LogManager.getLogger("test") } }); }
@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 } }
private static synchronized void init() { URL url = Log4j2Logger.class.getClassLoader().getResource("zebra_log4j2.xml"); try { if (null == url) { throw new ZebraException("log4j2 resource load failed"); } LoggerContext ctx = new LoggerContext("Zebra", null, url.toURI()); ctx.start(); context = ctx; } catch (Exception e) { throw new ZebraException("Fail to initialize log4j2", e); } }
public static LoggerContext getContext() { return new LoggerContext(); }
protected LoggerContext createContext(final String name, final URI configLocation) { return new LoggerContext(name, null, configLocation); }
@Override public LogentriesManager createManager(String name, FactoryData data) { return new LogentriesManager(new LoggerContext(name), name, data); } }
@Override public LoggerContext locateContext(final String name, final Object externalContext, final URI configLocation) { if (name == null) { LOGGER.error("A context name is required to locate a LoggerContext"); return null; } if (!CONTEXT_MAP.containsKey(name)) { final LoggerContext ctx = new LoggerContext(name, externalContext, configLocation); CONTEXT_MAP.putIfAbsent(name, ctx); } return CONTEXT_MAP.get(name); }
@Nonnull protected LoggerContext createLoggerContext(@Nonnull Log4J2BasedLoggingEnvironmentConfiguration requirement) { final org.apache.logging.log4j.core.LoggerContext result = new org.apache.logging.log4j.core.LoggerContext(FQCN); result.start(createConfigurationFor(requirement)); return result; }
private static LoggerContext locateContext(final Bundle bundle, final URI configLocation) { final String name = Objects.requireNonNull(bundle, "No Bundle provided").getSymbolicName(); final AtomicReference<WeakReference<LoggerContext>> ref = CONTEXT_MAP.get(name); if (ref == null) { final LoggerContext context = new LoggerContext(name, bundle, configLocation); CONTEXT_MAP.putIfAbsent(name, new AtomicReference<>(new WeakReference<>(context))); return CONTEXT_MAP.get(name).get().get(); } final WeakReference<LoggerContext> r = ref.get(); final LoggerContext ctx = r.get(); if (ctx == null) { final LoggerContext context = new LoggerContext(name, bundle, configLocation); ref.compareAndSet(r, new WeakReference<>(context)); return ref.get().get(); } final URI oldConfigLocation = ctx.getConfigLocation(); if (oldConfigLocation == null && configLocation != null) { LOGGER.debug("Setting bundle ({}) configuration to {}", name, configLocation); ctx.setConfigLocation(configLocation); } else if (oldConfigLocation != null && configLocation != null && !configLocation.equals(oldConfigLocation)) { LOGGER.warn("locateContext called with URI [{}], but existing LoggerContext has URI [{}]", configLocation, oldConfigLocation); } return ctx; } }
context = new LoggerContext(spaceId.getSpaceName(), Constants.SOFA_LOG_FIRST_INITIALIZE, confFile.toURI()); } else { context = new LoggerContext(spaceId.getSpaceName(), null, confFile.toURI());
private void configureDefaults() { if (m_log4jContext == null) { m_log4jContext = new LoggerContext(LOGGER_CONTEXT_NAME); } m_log4jContext.start(new DefaultConfiguration()); String levelName; levelName = m_bundleContext.getProperty( DEFAULT_SERVICE_LOG_LEVEL ); if( levelName == null ) { levelName = "DEBUG"; } else { levelName = levelName.trim(); } m_logLevel = convertLevel( levelName ); }
m_log4jContext = new AsyncLoggerContext(LOGGER_CONTEXT_NAME); } else { m_log4jContext = new LoggerContext(LOGGER_CONTEXT_NAME);
fis = new FileInputStream(new File(path)); ConfigurationSource cfgSrc = new ConfigurationSource(fis); this.context = new LoggerContext(this.ctxName); cfg = factory.getConfiguration(this.context, cfgSrc);