本文整理汇总了Java中org.apache.logging.log4j.core.LoggerContext.setExternalContext方法的典型用法代码示例。如果您正苦于以下问题:Java LoggerContext.setExternalContext方法的具体用法?Java LoggerContext.setExternalContext怎么用?Java LoggerContext.setExternalContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.logging.log4j.core.LoggerContext
的用法示例。
在下文中一共展示了LoggerContext.setExternalContext方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
/**
* Initializes the Logging Context.
* @param name The Context name.
* @param loader The ClassLoader for the Context (or null).
* @param configLocation The configuration for the logging context.
* @param externalContext The external context to be attached to the LoggerContext
* @return The LoggerContext.
*/
public static LoggerContext initialize(final String name, final ClassLoader loader, final URI configLocation,
final Object externalContext) {
try {
final org.apache.logging.log4j.spi.LoggerContext context = LogManager.getContext(loader, false, configLocation);
if (context instanceof LoggerContext) {
final LoggerContext ctx = (LoggerContext) context;
ContextAnchor.THREAD_CONTEXT.set(ctx);
if (externalContext != null) {
ctx.setExternalContext(externalContext);
}
final Configuration config = ConfigurationFactory.getInstance().getConfiguration(name, configLocation);
ctx.start(config);
ContextAnchor.THREAD_CONTEXT.remove();
return ctx;
} else {
LOGGER.error("LogManager returned an instance of {} which does not implement {}. Unable to initialize Log4j",
context.getClass().getName(), LoggerContext.class.getName());
}
} catch (final Exception ex) {
ex.printStackTrace();
}
return null;
}
示例2: getContext
import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
/**
* Loads the LoggerContext using the ContextSelector.
* @param fqcn The fully qualified class name of the caller.
* @param loader The ClassLoader to use or null.
* @param externalContext An external context (such as a ServletContext) to be associated with the LoggerContext.
* @param currentContext If true returns the current Context, if false returns the Context appropriate
* for the caller if a more appropriate Context can be determined.
* @param source The configuration source.
* @return The LoggerContext.
*/
public LoggerContext getContext(final String fqcn, final ClassLoader loader, final Object externalContext,
final boolean currentContext, final ConfigurationSource source) {
final LoggerContext ctx = selector.getContext(fqcn, loader, currentContext, null);
if (externalContext != null && ctx.getExternalContext() == null) {
ctx.setExternalContext(externalContext);
}
if (ctx.getState() == LifeCycle.State.INITIALIZED) {
if (source != null) {
ContextAnchor.THREAD_CONTEXT.set(ctx);
final Configuration config = ConfigurationFactory.getInstance().getConfiguration(ctx, source);
LOGGER.debug("Starting LoggerContext[name={}] from configuration {}", ctx.getName(), source);
ctx.start(config);
ContextAnchor.THREAD_CONTEXT.remove();
} else {
ctx.start();
}
}
return ctx;
}