本文整理了Java中org.apache.logging.log4j.LogManager.setFactory()
方法的一些代码示例,展示了LogManager.setFactory()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LogManager.setFactory()
方法的具体详情如下:
包路径:org.apache.logging.log4j.LogManager
类名称:LogManager
方法名:setFactory
[英]Sets the current LoggerContextFactory to use. Normally, the appropriate LoggerContextFactory is created at startup, but in certain environments, a LoggerContextFactory implementation may not be available at this point. Thus, an alternative LoggerContextFactory can be set at runtime.
Note that any Logger or LoggerContext objects already created will still be valid, but they will no longer be accessible through LogManager. Thus, it is a bad idea to use this method without a good reason! Generally, this method should be used only during startup before any code starts caching Logger objects.
[中]设置要使用的当前LoggerContextFactory。通常,在启动时会创建相应的LoggerContextFactory,但在某些环境中,此时可能无法使用LoggerContextFactory实现。因此,可以在运行时设置另一个LoggerContextFactory。
请注意,已经创建的任何Logger或LoggerContext对象仍然有效,但它们将不再可以通过LogManager访问。因此,在没有充分理由的情况下使用这种方法是个坏主意!通常,在任何代码开始缓存记录器对象之前,仅应在启动期间使用此方法。
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Override
protected void after() {
LogManager.setFactory(this.restoreLoggerContextFactory);
}
代码示例来源:origin: apache/hive
private static boolean checkAndSetAsyncLogging(final Configuration conf) {
final boolean asyncLogging = MetastoreConf.getBoolVar(conf, ConfVars.ASYNC_LOG_ENABLED);
if (asyncLogging) {
System.setProperty("Log4jContextSelector",
"org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
// default is ClassLoaderContextSelector which is created during automatic logging
// initialization in a static initialization block.
// Changing ContextSelector at runtime requires creating new context factory which will
// internally create new context selector based on system property.
LogManager.setFactory(new Log4jContextFactory());
}
return asyncLogging;
}
代码示例来源:origin: apache/hive
public static boolean checkAndSetAsyncLogging(final Configuration conf) {
final boolean asyncLogging = HiveConf.getBoolVar(conf, ConfVars.HIVE_ASYNC_LOG_ENABLED);
if (asyncLogging) {
System.setProperty("Log4jContextSelector",
"org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
// default is ClassLoaderContextSelector which is created during automatic logging
// initialization in a static initialization block.
// Changing ContextSelector at runtime requires creating new context factory which will
// internally create new context selector based on system property.
LogManager.setFactory(new Log4jContextFactory());
}
return asyncLogging;
}
代码示例来源:origin: org.apache.logging.log4j/log4j-api
@Override
protected void before() throws Throwable {
this.restoreLoggerContextFactory = LogManager.getFactory();
LogManager.setFactory(this.loggerContextFactory);
}
代码示例来源:origin: mulesoft/mule
@Test
public void disposesLogContextFactory() throws Exception {
final LoggerContextFactory originalFactory = LogManager.getFactory();
try {
MuleLog4jContextFactory contextFactory = mock(MuleLog4jContextFactory.class);
LogManager.setFactory(contextFactory);
container.stop();
verify(contextFactory).dispose();
} finally {
LogManager.setFactory(originalFactory);
}
}
代码示例来源:origin: org.apache.hive/hive-standalone-metastore
private static boolean checkAndSetAsyncLogging(final Configuration conf) {
final boolean asyncLogging = MetastoreConf.getBoolVar(conf, ConfVars.ASYNC_LOG_ENABLED);
if (asyncLogging) {
System.setProperty("Log4jContextSelector",
"org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
// default is ClassLoaderContextSelector which is created during automatic logging
// initialization in a static initialization block.
// Changing ContextSelector at runtime requires creating new context factory which will
// internally create new context selector based on system property.
LogManager.setFactory(new Log4jContextFactory());
}
return asyncLogging;
}
代码示例来源:origin: org.apache.hive/hive-common
public static boolean checkAndSetAsyncLogging(final Configuration conf) {
final boolean asyncLogging = HiveConf.getBoolVar(conf, ConfVars.HIVE_ASYNC_LOG_ENABLED);
if (asyncLogging) {
System.setProperty("Log4jContextSelector",
"org.apache.logging.log4j.core.async.AsyncLoggerContextSelector");
// default is ClassLoaderContextSelector which is created during automatic logging
// initialization in a static initialization block.
// Changing ContextSelector at runtime requires creating new context factory which will
// internally create new context selector based on system property.
LogManager.setFactory(new Log4jContextFactory());
}
return asyncLogging;
}
代码示例来源:origin: org.echocat.jomon/runtime
LogManager.setFactory(_originalFactory);
} finally {
try {
代码示例来源:origin: org.echocat.jomon/runtime
public void init(@Nonnull Log4J2BasedLoggingEnvironmentConfiguration with) {
synchronized (this) {
if (_factory == null) {
_originalFactory = findOriginalFactory();
_factory = new LoggerContextFactoryImpl(createLoggerContext(with));
_loggerFactory = new LoggerFactory(_factory);
LogManager.setFactory(_factory);
_loggerFactoryRegistration = LoggerFactoryRegistry.register(_loggerFactory);
if (with.isInstallSl4jRequired()) {
_installation = Slf4jUtils.tryInstallSlf4jBridges(_loggerFactory);
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!