本文整理汇总了Java中org.apache.logging.log4j.core.impl.Log4jContextFactory类的典型用法代码示例。如果您正苦于以下问题:Java Log4jContextFactory类的具体用法?Java Log4jContextFactory怎么用?Java Log4jContextFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Log4jContextFactory类属于org.apache.logging.log4j.core.impl包,在下文中一共展示了Log4jContextFactory类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getActiveLogFilePaths
import org.apache.logging.log4j.core.impl.Log4jContextFactory; //导入依赖的package包/类
/**
* We cannot presume that the default file name/location setting won't be changed by the user.
* Therefore, we should be able to retrieve that info from the underlying logging mechanism
* by iterating over appenders.
*/
private List<Path> getActiveLogFilePaths() {
LoggerContextFactory factory = LogManager.getFactory();
ContextSelector selector = ((Log4jContextFactory) factory).getSelector();
List<Path> fileNameList = new ArrayList<>();
for (LoggerContext ctx : selector.getLoggerContexts()) {
for (Appender appender : ctx.getConfiguration().getAppenders().values()) {
String fileName = extractFileName(appender);
if (fileName != null) {
fileNameList.add(Paths.get(fileName));
}
}
}
return fileNameList;
}
开发者ID:RWTH-i5-IDSG,项目名称:xsharing-services-router,代码行数:21,代码来源:LogFileRetriever.java
示例2: setup
import org.apache.logging.log4j.core.impl.Log4jContextFactory; //导入依赖的package包/类
@Before
public void setup() throws Exception {
// Create mock objects
mockLog4jContextFactory = mock(Log4jContextFactory.class);
whenNew(Log4jContextFactory.class).withNoArguments().thenReturn(mockLog4jContextFactory);
mockLoggerContext = mock(LoggerContext.class);
mockLogger = mock(Logger.class);
when(mockLog4jContextFactory.getContext(anyString(), any(ClassLoader.class), any(), anyBoolean(), any(URI.class), anyString())).thenReturn(mockLoggerContext);
when(mockLoggerContext.getRootLogger()).thenReturn(mockLogger);
mockRequest = mock(Request.class);
mockResponse = mock(Response.class);
mockAccessLog = mock(AccessLog.class);
whenNew(AccessLog.class).withArguments(mockRequest, mockResponse).thenReturn(mockAccessLog);
// Create actual objects
enabledSupplier = () -> true;
disabledSupplier = () -> false;
failedAccessLog = new TestLog4JAccessLog(NON_EXISTING_FILE_PATH, enabledSupplier);
String filePath = getClass().getClassLoader().getResource(ACCESS_CONFIG_FILE_PATH).getPath();
enabledAccessLog = new TestLog4JAccessLog(filePath, enabledSupplier);
disabledAccessLog = new TestLog4JAccessLog(filePath, disabledSupplier);
}
开发者ID:flipkart-incubator,项目名称:Poseidon,代码行数:23,代码来源:Log4JAccessLogTest.java
示例3: initialize
import org.apache.logging.log4j.core.impl.Log4jContextFactory; //导入依赖的package包/类
/**
* Initializes the Logging Context.
* @param loader The ClassLoader for the Context (or null).
* @param source The InputSource for the configuration.
* @param externalContext The external context to be attached to the LoggerContext.
* @return The LoggerContext.
*/
public static LoggerContext initialize(final ClassLoader loader,
final ConfigurationSource source,
final Object externalContext)
{
try {
final Log4jContextFactory factory = getFactory();
return factory == null ? null :
factory.getContext(FQCN, loader, externalContext, false, source);
} catch (final Exception ex) {
LOGGER.error("There was a problem obtaining a LoggerContext using the configuration source [{}]", source, ex);
}
return null;
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:23,代码来源:Configurator.java
示例4: getContexts
import org.apache.logging.log4j.core.impl.Log4jContextFactory; //导入依赖的package包/类
public static List<? extends LoggerContext> getContexts() {
LoggerContextFactory factory = org.apache.logging.log4j.LogManager.getFactory();
if(factory instanceof SimpleLoggerContextFactory) {
return Collections.singletonList(factory.getContext(null, null, null, true));
}
return ((Log4jContextFactory) org.apache.logging.log4j.LogManager.getFactory()).getSelector().getLoggerContexts();
}
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:8,代码来源:Logging.java
示例5: doStart
import org.apache.logging.log4j.core.impl.Log4jContextFactory; //导入依赖的package包/类
@Override
protected void doStart() throws Exception {
File accessConfigFile = new File(accessConfigFilePath);
if (!accessConfigFile.isFile()) {
throw new Exception("Log4J access config file not found: " + accessConfigFilePath);
}
loggerContext = new Log4jContextFactory().getContext(Log4JAccessLog.class.getName(), null, null, true, accessConfigFile.toURI(), "PoseidonLog4JAccess");
logger = loggerContext.getRootLogger();
}
开发者ID:flipkart-incubator,项目名称:Poseidon,代码行数:11,代码来源:Log4JAccessLog.java
示例6: initializeJndi
import org.apache.logging.log4j.core.impl.Log4jContextFactory; //导入依赖的package包/类
private void initializeJndi(final String location) throws UnavailableException {
URI configLocation = null;
if (location != null) {
try {
configLocation = new URI(location);
} catch (final Exception e) {
this.servletContext.log("Unable to convert configuration location [" + location + "] to a URI!", e);
}
}
if (this.name == null) {
throw new UnavailableException("A log4jContextName context parameter is required");
}
LoggerContext loggerContext;
final LoggerContextFactory factory = LogManager.getFactory();
if (factory instanceof Log4jContextFactory) {
final ContextSelector selector = ((Log4jContextFactory) factory).getSelector();
if (selector instanceof NamedContextSelector) {
this.selector = (NamedContextSelector) selector;
loggerContext = this.selector.locateContext(this.name, this.servletContext, configLocation);
ContextAnchor.THREAD_CONTEXT.set(loggerContext);
if (loggerContext.getStatus() == LoggerContext.Status.INITIALIZED) {
loggerContext.start();
}
ContextAnchor.THREAD_CONTEXT.remove();
} else {
this.servletContext.log("Potential problem: Selector is not an instance of NamedContextSelector.");
return;
}
} else {
this.servletContext.log("Potential problem: Factory is not an instance of Log4jContextFactory.");
return;
}
this.loggerContext = loggerContext;
this.servletContext.log("Created logger context for [" + this.name + "] using [" +
loggerContext.getClass().getClassLoader() + "].");
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:39,代码来源:Log4jWebInitializerImpl.java
示例7: initializeJndi
import org.apache.logging.log4j.core.impl.Log4jContextFactory; //导入依赖的package包/类
private void initializeJndi(final String location) {
final URI configLocation = getConfigURI(location);
if (this.name == null) {
throw new IllegalStateException("A log4jContextName context parameter is required");
}
LoggerContext context;
final LoggerContextFactory factory = LogManager.getFactory();
if (factory instanceof Log4jContextFactory) {
final ContextSelector selector = ((Log4jContextFactory) factory).getSelector();
if (selector instanceof NamedContextSelector) {
this.namedContextSelector = (NamedContextSelector) selector;
context = this.namedContextSelector.locateContext(this.name, this.servletContext, configLocation);
ContextAnchor.THREAD_CONTEXT.set(context);
if (context.isInitialized()) {
context.start();
}
ContextAnchor.THREAD_CONTEXT.remove();
} else {
LOGGER.warn("Potential problem: Selector is not an instance of NamedContextSelector.");
return;
}
} else {
LOGGER.warn("Potential problem: LoggerContextFactory is not an instance of Log4jContextFactory.");
return;
}
this.loggerContext = context;
LOGGER.debug("Created logger context for [{}] using [{}].", this.name, context.getClass().getClassLoader());
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:31,代码来源:Log4jWebInitializerImpl.java
示例8: getContextSelector
import org.apache.logging.log4j.core.impl.Log4jContextFactory; //导入依赖的package包/类
/**
* Returns the {@code ContextSelector} of the current {@code Log4jContextFactory}.
*
* @return the {@code ContextSelector} of the current {@code Log4jContextFactory}
*/
private static ContextSelector getContextSelector() {
final LoggerContextFactory factory = LogManager.getFactory();
if (factory instanceof Log4jContextFactory) {
final ContextSelector selector = ((Log4jContextFactory) factory).getSelector();
return selector;
}
return null;
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:14,代码来源:Server.java
示例9: getFactory
import org.apache.logging.log4j.core.impl.Log4jContextFactory; //导入依赖的package包/类
private static Log4jContextFactory getFactory() {
final LoggerContextFactory factory = LogManager.getFactory();
if (factory instanceof Log4jContextFactory) {
return (Log4jContextFactory) factory;
} else if (factory != null) {
LOGGER.error("LogManager returned an instance of {} which does not implement {}. Unable to initialize Log4j.",
factory.getClass().getName(), Log4jContextFactory.class.getName());
return null;
} else {
LOGGER.fatal("LogManager did not return a LoggerContextFactory. This indicates something has gone terribly wrong!");
return null;
}
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:14,代码来源:Configurator.java
示例10: testShutdownCallbackRegistry
import org.apache.logging.log4j.core.impl.Log4jContextFactory; //导入依赖的package包/类
@Test
public void testShutdownCallbackRegistry() throws Exception {
final LoggerContext context = ctx.getLoggerContext();
assertTrue("LoggerContext should be started", context.isStarted());
assertThat(Registry.CALLBACKS, hasSize(1));
Registry.shutdown();
assertTrue("LoggerContext should be stopped", context.isStopped());
assertThat(Registry.CALLBACKS, hasSize(0));
final ContextSelector selector = ((Log4jContextFactory) LogManager.getFactory()).getSelector();
assertThat(selector.getLoggerContexts(), not(hasItem(context)));
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:12,代码来源:ShutdownCallbackRegistryTest.java
示例11: testShutdownHookDisabled
import org.apache.logging.log4j.core.impl.Log4jContextFactory; //导入依赖的package包/类
@Test
public void testShutdownHookDisabled() {
assertFalse(
"Shutdown hook should be disabled by default in web applications",
((Log4jContextFactory) LogManager.getFactory()).isShutdownHookEnabled());
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:7,代码来源:PropertyTest.java
注:本文中的org.apache.logging.log4j.core.impl.Log4jContextFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论