org.apache.log4j.spi.LoggerRepository Java Examples
The following examples show how to use
org.apache.log4j.spi.LoggerRepository.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Log4jTest.java From sofa-common-tools with Apache License 2.0 | 6 votes |
@Test public void testIndependentSpaceLog4j() { LoggerRepository repo1 = new Hierarchy(new RootLogger((Level) Level.DEBUG)); URL url1 = LogbackTest.class.getResource("/com/alipay/sofa/rpc/log/log4j/log-conf.xml"); OptionConverter.selectAndConfigure(url1, null, repo1); Logger logger1 = repo1.getLogger("com.foo.Bar"); Assert.assertNotNull(logger1); //log4j logger 2 LoggerRepository repo2 = new Hierarchy(new RootLogger((Level) Level.DEBUG)); URL url2 = LogbackTest.class.getResource("/com/alipay/sofa/rpc/log/log4j/log4j_b.xml"); OptionConverter.selectAndConfigure(url2, null, repo2); Logger logger2 = repo1.getLogger("com.foo.Bar2"); Assert.assertNotNull(logger2); Assert.assertNotSame(logger1, logger2); }
Example #2
Source File: Log4jTest.java From sofa-common-tools with Apache License 2.0 | 6 votes |
@Test public void testLocalProperties() throws NoSuchFieldException, IllegalAccessException { LoggerRepository repo2 = new Hierarchy(new RootLogger((Level) Level.DEBUG)); URL url2 = LogbackTest.class.getResource("/com/alipay/sofa/rpc/log/log4j/log4j_b.xml"); DOMConfigurator domConfigurator = new DOMConfigurator(); Field field = DOMConfigurator.class.getDeclaredField("props"); field.setAccessible(true); Properties props = new Properties(); field.set(domConfigurator, props); props.put("hello", "defaultb"); domConfigurator.doConfigure(url2, repo2); Logger logger2 = repo2.getLogger("com.foo.Bar3"); Assert.assertTrue(logger2.getAllAppenders().hasMoreElements()); }
Example #3
Source File: HaxeDebugLogger.java From intellij-haxe with Apache License 2.0 | 6 votes |
private synchronized void captureState(LoggerRepository hierarchy) throws IllegalStateException { if (null == hierarchy) { throw new IllegalArgumentException("Null Hierarchy is not allowed."); } if (null != capturedHierarchy && capturedHierarchy != hierarchy) { throw new IllegalStateException("Log configurations is already holding a captured hierarchy."); } capturedHierarchy = hierarchy; threshold = hierarchy.getThreshold(); Enumeration e = hierarchy.getCurrentLoggers(); while (e.hasMoreElements()) { Logger l = (Logger)e.nextElement(); Level v = l.getLevel(); // No point in capturing or restoring NULL loggers. if (null != v) { capturedConfiguration.addConfiguration(l.getName(), v); } } }
Example #4
Source File: TezLog4jConfigurator.java From tez with Apache License 2.0 | 6 votes |
public void doConfigure(Properties properties, LoggerRepository repository) { String logParams = System.getenv(TezConstants.TEZ_CONTAINER_LOG_PARAMS); if (logParams != null) { String []parts = logParams.split(TezConstants.TEZ_CONTAINER_LOG_PARAMS_SEPARATOR); for (String logParam : parts) { String [] logParamParts = logParam.split("="); if (logParamParts.length == 2) { String loggerName = "log4j.logger." + logParamParts[0]; String logLevel = logParamParts[1].toUpperCase(Locale.ENGLISH); properties.setProperty(loggerName, logLevel); } else { // Cannot use Log4J logging from here. System.out.println("TezLog4jConfigurator Ignoring invalid log parameter [" + logParam + "]"); continue; } } } super.doConfigure(properties, repository); }
Example #5
Source File: PropertyConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** Read configuration options from url <code>configURL</code>. */ public void doConfigure(java.net.URL configURL, LoggerRepository hierarchy) { Properties props = new Properties(); LogLog.debug("Reading configuration from URL " + configURL); InputStream istream = null; try { istream = configURL.openStream(); props.load(istream); } catch (Exception e) { LogLog.error("Could not read configuration file from URL [" + configURL + "].", e); LogLog.error("Ignoring configuration file [" + configURL +"]."); return; } finally { if (istream != null) { try { istream.close(); } catch(Exception ignore) { } } } doConfigure(props, hierarchy); }
Example #6
Source File: PropertyConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
void configureRootCategory(Properties props, LoggerRepository hierarchy) { String effectiveFrefix = ROOT_LOGGER_PREFIX; String value = OptionConverter.findAndSubst(ROOT_LOGGER_PREFIX, props); if(value == null) { value = OptionConverter.findAndSubst(ROOT_CATEGORY_PREFIX, props); effectiveFrefix = ROOT_CATEGORY_PREFIX; } if(value == null) LogLog.debug("Could not find root logger information. Is this OK?"); else { Logger root = hierarchy.getRootLogger(); synchronized(root) { parseCategory(props, root, effectiveFrefix, INTERNAL_ROOT_NAME, value); } } }
Example #7
Source File: DOMConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** Configure log4j by reading in a log4j.dtd compliant XML configuration file. */ protected void doConfigure(final InputSource inputSource, LoggerRepository repository) throws FactoryConfigurationError { if (inputSource.getSystemId() == null) { inputSource.setSystemId("dummy://log4j.dtd"); } ParseAction action = new ParseAction() { public Document parse(final DocumentBuilder parser) throws SAXException, IOException { return parser.parse(inputSource); } public String toString() { return "input source [" + inputSource.toString() + "]"; } }; doConfigure(action, repository); }
Example #8
Source File: DOMConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** Configure log4j by reading in a log4j.dtd compliant XML configuration file. */ public void doConfigure(final Reader reader, LoggerRepository repository) throws FactoryConfigurationError { ParseAction action = new ParseAction() { public Document parse(final DocumentBuilder parser) throws SAXException, IOException { InputSource inputSource = new InputSource(reader); inputSource.setSystemId("dummy://log4j.dtd"); return parser.parse(inputSource); } public String toString() { return "reader [" + reader.toString() + "]"; } }; doConfigure(action, repository); }
Example #9
Source File: DOMConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** Configure log4j by reading in a log4j.dtd compliant XML configuration file. */ public void doConfigure(final InputStream inputStream, LoggerRepository repository) throws FactoryConfigurationError { ParseAction action = new ParseAction() { public Document parse(final DocumentBuilder parser) throws SAXException, IOException { InputSource inputSource = new InputSource(inputStream); inputSource.setSystemId("dummy://log4j.dtd"); return parser.parse(inputSource); } public String toString() { return "input stream [" + inputStream.toString() + "]"; } }; doConfigure(action, repository); }
Example #10
Source File: ThreadLocalLogLevelManager.java From olat with Apache License 2.0 | 5 votes |
public ThreadLocalAwareLoggerRepository(Logger originalRoot, LoggerRepository parentRepository, LoggerFactory loggerFactory) { super(originalRoot); if (loggerFactory == null) { throw new IllegalArgumentException("loggerFactory must not be null"); } loggerFactory_ = loggerFactory; parentLoggerRepository_ = parentRepository; }
Example #11
Source File: ThreadLocalLogLevelManager.java From olat with Apache License 2.0 | 5 votes |
/** * Installs the ThreadLogManager in this system. * <p> * Note that this can fail if some other framework has done a call to LogManager.setRepositorySelector with a guard already. * * @param logMessageModifier * optional implementation of LogMessageModifier which allows messages to be modified should they be affected by a threadlocal loglevel overwrite. This * allows for example for messages to be prepended with a token so that they can be easier found in the log */ void install(final LogMessageModifier logMessageModifier) { try { final LoggerFactory loggerFactory = new LoggerFactory() { @SuppressWarnings("synthetic-access") @Override public Logger makeNewLoggerInstance(String name) { return new ThreadLocalAwareLogger(name, threadLocalLogLevel_, logMessageModifier); } }; final Logger originalRootLogger = LogManager.getRootLogger(); final LoggerRepository parentRepository = originalRootLogger.getLoggerRepository(); final LoggerRepository repository = new ThreadLocalAwareLoggerRepository(originalRootLogger, parentRepository, loggerFactory); LogManager.setRepositorySelector(new RepositorySelector() { @Override public LoggerRepository getLoggerRepository() { return repository; } }, guard); } catch (IllegalArgumentException re) { // thrown by LogManager.setRepositorySelector log.error("Could not install ThreadLocalLogLevelManager", re); } }
Example #12
Source File: ThreadLocalLogLevelManager.java From olat with Apache License 2.0 | 5 votes |
public ThreadLocalAwareLoggerRepository(Logger originalRoot, LoggerRepository parentRepository, LoggerFactory loggerFactory) { super(originalRoot); if (loggerFactory == null) { throw new IllegalArgumentException("loggerFactory must not be null"); } loggerFactory_ = loggerFactory; parentLoggerRepository_ = parentRepository; }
Example #13
Source File: ThreadLocalLogLevelManager.java From olat with Apache License 2.0 | 5 votes |
/** * Installs the ThreadLogManager in this system. * <p> * Note that this can fail if some other framework has done a call to LogManager.setRepositorySelector with a guard already. * * @param logMessageModifier * optional implementation of LogMessageModifier which allows messages to be modified should they be affected by a threadlocal loglevel overwrite. This * allows for example for messages to be prepended with a token so that they can be easier found in the log */ void install(final LogMessageModifier logMessageModifier) { try { final LoggerFactory loggerFactory = new LoggerFactory() { @SuppressWarnings("synthetic-access") @Override public Logger makeNewLoggerInstance(String name) { return new ThreadLocalAwareLogger(name, threadLocalLogLevel_, logMessageModifier); } }; final Logger originalRootLogger = LogManager.getRootLogger(); final LoggerRepository parentRepository = originalRootLogger.getLoggerRepository(); final LoggerRepository repository = new ThreadLocalAwareLoggerRepository(originalRootLogger, parentRepository, loggerFactory); LogManager.setRepositorySelector(new RepositorySelector() { @Override public LoggerRepository getLoggerRepository() { return repository; } }, guard); } catch (IllegalArgumentException re) { // thrown by LogManager.setRepositorySelector log.error("Could not install ThreadLocalLogLevelManager", re); } }
Example #14
Source File: HaxeDebugLogger.java From intellij-haxe with Apache License 2.0 | 5 votes |
public synchronized void mute(LoggerRepository hierarchy) throws IllegalStateException { if (null == hierarchy) { throw new IllegalArgumentException("Null Hierarchy is not allowed."); } if (null != capturedHierarchy && capturedHierarchy != hierarchy) { throw new IllegalStateException("Trying to mute a hierarchy that is not the one previously captured."); } captureState(hierarchy); hierarchy.setThreshold(Level.OFF); }
Example #15
Source File: DOMConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public void doConfigure(final URL url, LoggerRepository repository) { ParseAction action = new ParseAction() { public Document parse(final DocumentBuilder parser) throws SAXException, IOException { return parser.parse(url.toString()); } public String toString() { return "url [" + url.toString() + "]"; } }; doConfigure(action, repository); }
Example #16
Source File: PropertyConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** Parse non-root elements, such non-root categories and renderers. */ protected void parseCatsAndRenderers(Properties props, LoggerRepository hierarchy) { Enumeration enumeration = props.propertyNames(); while(enumeration.hasMoreElements()) { String key = (String) enumeration.nextElement(); if(key.startsWith(CATEGORY_PREFIX) || key.startsWith(LOGGER_PREFIX)) { String loggerName = null; if(key.startsWith(CATEGORY_PREFIX)) { loggerName = key.substring(CATEGORY_PREFIX.length()); } else if(key.startsWith(LOGGER_PREFIX)) { loggerName = key.substring(LOGGER_PREFIX.length()); } String value = OptionConverter.findAndSubst(key, props); Logger logger = hierarchy.getLogger(loggerName, loggerFactory); synchronized(logger) { parseCategory(props, logger, key, loggerName, value); parseAdditivityForLogger(props, logger, loggerName); } } else if(key.startsWith(RENDERER_PREFIX)) { String renderedClass = key.substring(RENDERER_PREFIX.length()); String renderingClass = OptionConverter.findAndSubst(key, props); if(hierarchy instanceof RendererSupport) { RendererMap.addRenderer((RendererSupport) hierarchy, renderedClass, renderingClass); } } } }
Example #17
Source File: DOMConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public void doConfigure(final String filename, LoggerRepository repository) { ParseAction action = new ParseAction() { public Document parse(final DocumentBuilder parser) throws SAXException, IOException { return parser.parse(new File(filename)); } public String toString() { return "file [" + filename + "]"; } }; doConfigure(action, repository); }
Example #18
Source File: PropertyConfigurator.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** Read configuration options from <code>properties</code>. See {@link #doConfigure(String, LoggerRepository)} for the expected format. */ public void doConfigure(Properties properties, LoggerRepository hierarchy) { String value = properties.getProperty(LogLog.DEBUG_KEY); if(value == null) { value = properties.getProperty("log4j.configDebug"); if(value != null) LogLog.warn("[log4j.configDebug] is deprecated. Use [log4j.debug] instead."); } if(value != null) { LogLog.setInternalDebugging(OptionConverter.toBoolean(value, true)); } // // if log4j.reset=true then // reset hierarchy String reset = properties.getProperty(RESET_KEY); if (reset != null && OptionConverter.toBoolean(reset, false)) { hierarchy.resetConfiguration(); } String thresholdStr = OptionConverter.findAndSubst(THRESHOLD_PREFIX, properties); if(thresholdStr != null) { hierarchy.setThreshold(OptionConverter.toLevel(thresholdStr, (Level) Level.ALL)); LogLog.debug("Hierarchy threshold set to ["+hierarchy.getThreshold()+"]."); } configureRootCategory(properties, hierarchy); configureLoggerFactory(properties); parseCatsAndRenderers(properties, hierarchy); LogLog.debug("Finished configuring."); // We don't want to hold references to appenders preventing their // garbage collection. registry.clear(); }
Example #19
Source File: LogManager.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public static LoggerRepository getLoggerRepository() { return REPOSITORY; }
Example #20
Source File: DOMConfigurator.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public void doConfigure(final Element element, final LoggerRepository repository) { }
Example #21
Source File: LoggerUtil.java From Bats with Apache License 2.0 | 4 votes |
private DelegatingLoggerRepository(LoggerRepository loggerRepository) { this.loggerRepository = loggerRepository; }
Example #22
Source File: DOMConfigurator.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public void doConfigure(final Reader reader, final LoggerRepository repository) throws FactoryConfigurationError { }
Example #23
Source File: DOMConfigurator.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public void doConfigure(final InputStream inputStream, final LoggerRepository repository) throws FactoryConfigurationError { }
Example #24
Source File: SpringBindingModuleTest.java From attic-rave with Apache License 2.0 | 4 votes |
@Test public void bindsAlternatePackage() { LoggerRepository string = injector.getInstance(LoggerRepository.class); assertThat(string, is(notNullValue())); }
Example #25
Source File: DOMConfigurator.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public void doConfigure(final URL url, final LoggerRepository repository) { }
Example #26
Source File: DOMConfigurator.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public void doConfigure(final String filename, final LoggerRepository repository) { }
Example #27
Source File: DOMConfigurator.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public void doConfigure(final String filename, final LoggerRepository repository) { }
Example #28
Source File: DOMConfigurator.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public void doConfigure(final URL url, final LoggerRepository repository) { }
Example #29
Source File: DOMConfigurator.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public void doConfigure(final InputStream inputStream, final LoggerRepository repository) throws FactoryConfigurationError { }
Example #30
Source File: DOMConfigurator.java From logging-log4j2 with Apache License 2.0 | 4 votes |
public void doConfigure(final Reader reader, final LoggerRepository repository) throws FactoryConfigurationError { }