Java 类org.apache.log4j.spi.RepositorySelector 实例源码
项目:olat
文件:ThreadLocalLogLevelManager.java
/**
* 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);
}
}
项目:olat
文件:ThreadLocalLogLevelManager.java
/**
* 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);
}
}
项目:t4f-data
文件:AppRespositorySelector.java
public static synchronized void init(ServletContext servletContext)
throws ServletException {
if (!initialized) // set the global RepositorySelector
{
defaultRepository = LoggerFactory.getLoggerRepository();
RepositorySelector theSelector = new AppRespositorySelector();
LogManager.setRepositorySelector(theSelector, guard);
initialized = true;
}
Hierarchy hierarchy = new Hierarchy(new RootLogger(Level.DEBUG));
loadLog4JConfig(servletContext, hierarchy);
ClassLoader loader = Thread.currentThread().getContextClassLoader();
repositories.put(loader, hierarchy);
}
项目:cacheonix-core
文件:LogManager.java
/**
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;
}
项目:daq-eclipse
文件:LogManager.java
/**
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;
}
项目:nabs
文件:LogManager.java
/**
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;
}
项目:logging
文件:FoundationLogger.java
/**
* Initialize that Foundation Logging library.
*/
static void init() {// NOPMD
determineIfNTEventLogIsSupported();
URL resource = null;
final String configurationOptionStr = OptionConverter.getSystemProperty(DEFAULT_CONFIGURATION_KEY, null);
if (configurationOptionStr != null) {
try {
resource = new URL(configurationOptionStr);
} catch (MalformedURLException ex) {
// so, resource is not a URL:
// attempt to get the resource from the class path
resource = Loader.getResource(configurationOptionStr);
}
}
if (resource == null) {
resource = Loader.getResource(DEFAULT_CONFIGURATION_FILE); // NOPMD
}
if (resource == null) {
System.err.println("[FoundationLogger] Can not find resource: " + DEFAULT_CONFIGURATION_FILE); // NOPMD
throw new FoundationIOException("Can not find resource: " + DEFAULT_CONFIGURATION_FILE); // NOPMD
}
// update the log manager to use the Foundation repository.
final RepositorySelector foundationRepositorySelector = new FoundationRepositorySelector(FoundationLogFactory.foundationLogHierarchy);
LogManager.setRepositorySelector(foundationRepositorySelector, null);
// set logger to info so we always want to see these logs even if root
// is set to ERROR.
final Logger logger = getLogger(FoundationLogger.class);
final String logPropFile = resource.getPath();
log4jConfigProps = getLogProperties(resource);
// select and configure again so the loggers are created with the right
// level after the repository selector was updated.
OptionConverter.selectAndConfigure(resource, null, FoundationLogFactory.foundationLogHierarchy);
// start watching for property changes
setUpPropFileReloading(logger, logPropFile, log4jConfigProps);
// add syslog appender or windows event viewer appender
// setupOSSystemLog(logger, log4jConfigProps);
// parseMarkerPatterns(log4jConfigProps);
// parseMarkerPurePattern(log4jConfigProps);
// udpateMarkerStructuredLogOverrideMap(logger);
AbstractFoundationLoggingMarker.init();
updateSniffingLoggersLevel(logger);
setupJULSupport(resource);
}
项目:log4j2
文件:LogManager.java
/**
* 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 {
}
项目:logging-log4j2
文件:LogManager.java
/**
* 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 {
}