org.apache.log4j.spi.RepositorySelector Java Examples

The following examples show how to use org.apache.log4j.spi.RepositorySelector. 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: ThreadLocalLogLevelManager.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #2
Source File: ThreadLocalLogLevelManager.java    From olat with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #3
Source File: LogManager.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
   Sets <code>LoggerFactory</code> but only if the correct
   <em>guard</em> is passed as parameter.
   
   <p>Initally the guard is null.  If the guard is
   <code>null</code>, then invoking this method sets the logger
   factory and the guard. Following invocations will throw a {@link
   IllegalArgumentException}, unless the previously set
   <code>guard</code> is passed as the second parameter.

   <p>This allows a high-level component to set the {@link
   RepositorySelector} used by the <code>LogManager</code>.
   
   <p>For example, when tomcat starts it will be able to install its
   own repository selector. However, if and when Tomcat is embedded
   within JBoss, then JBoss will install its own repository selector
   and Tomcat will use the repository selector set by its container,
   JBoss.  */
static
public
void setRepositorySelector(RepositorySelector selector, Object guard) 
                                               throws IllegalArgumentException {
  if((LogManager.guard != null) && (LogManager.guard != guard)) {
    throw new IllegalArgumentException(
         "Attempted to reset the LoggerFactory without possessing the guard.");
  }

  if(selector == null) {
    throw new IllegalArgumentException("RepositorySelector must be non-null.");
  }

  LogManager.guard = guard;
  LogManager.repositorySelector = selector;
}
 
Example #4
Source File: LogManager.java    From logging-log4j2 with Apache License 2.0 2 votes vote down vote up
/**
 * No-op implementation.
 * @param selector The RepositorySelector.
 * @param guard prevents calls at the incorrect time.
 * @throws IllegalArgumentException if a parameter is invalid.
 */
public static void setRepositorySelector(final RepositorySelector selector, final Object guard)
    throws IllegalArgumentException {
}
 
Example #5
Source File: LogManager.java    From logging-log4j2 with Apache License 2.0 2 votes vote down vote up
/**
 * No-op implementation.
 * @param selector The RepositorySelector.
 * @param guard prevents calls at the incorrect time.
 * @throws IllegalArgumentException if a parameter is invalid.
 */
public static void setRepositorySelector(final RepositorySelector selector, final Object guard)
    throws IllegalArgumentException {
}