当前位置: 首页>>代码示例>>Java>>正文


Java LoggerContext.start方法代码示例

本文整理汇总了Java中org.apache.logging.log4j.core.LoggerContext.start方法的典型用法代码示例。如果您正苦于以下问题:Java LoggerContext.start方法的具体用法?Java LoggerContext.start怎么用?Java LoggerContext.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.logging.log4j.core.LoggerContext的用法示例。


在下文中一共展示了LoggerContext.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadConfiguration

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
protected void loadConfiguration(String location, LogFile logFile) {
	Assert.notNull(location, "Location must not be null");
	if (logFile != null) {
		logFile.applyToSystemProperties();
	}
	try {
		LoggerContext ctx = getLoggerContext();
		URL url = ResourceUtils.getURL(location);
		ConfigurationSource source = getConfigurationSource(url);
		ctx.start(ConfigurationFactory.getInstance().getConfiguration(source));
	}
	catch (Exception ex) {
		throw new IllegalStateException(
				"Could not initialize Log4J2 logging from " + location, ex);
	}
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:17,代码来源:Log4J2LoggingSystem.java

示例2: loadLogger

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
/**
 * <p>
 * This method loads the required properties into log4j for the logger
 * </p>
 * 
 * @param logFileDir
 *            Log file directory
 * @param taskAttemptID
 *            The task attempt id
 * 
 * @throws IOException
 *             If any error occurs
 * @throws URISyntaxException
 * @throws SAXException
 * @throws ParserConfigurationException
 * @throws TransformerException
 */
public static void loadLogger(String logFileDir, String taskAttemptID) throws IOException, URISyntaxException, ParserConfigurationException,
		SAXException, TransformerException {
    LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    ctx.reconfigure();
       Configuration config = ctx.getConfiguration();
       MemoryMappedFileAppender memoryMappedfileAppender = createMemoryMappedFileAppender(config, LOG_APPENDER_NAME + taskAttemptID, logFileDir, taskAttemptID, 0);
       memoryMappedfileAppender.start();
    AppenderRef[] ar = new AppenderRef [1];
       ar[0] = AppenderRef.createAppenderRef(LOG_APPENDER_NAME + taskAttemptID , Level.INFO, null);
       LoggerConfig lgf = LoggerConfig.createLogger("false",Level.INFO , LOG_CATEGORY + taskAttemptID , null, ar, null, config, null);
       config.addLogger(LOG_CATEGORY + taskAttemptID, lgf);
       ctx.getLogger(LOG_CATEGORY + taskAttemptID).addAppender(memoryMappedfileAppender);
       ctx.updateLoggers();
       ctx.start();
	mapReduceLoggers = new ArrayList<Logger>(1);
	mapReduceLoggers.add(LogManager.getLogger(LOG_CATEGORY + taskAttemptID));
	LOG.debug("Finished loading logger");

}
 
开发者ID:Impetus,项目名称:jumbune,代码行数:37,代码来源:LoggerUtil.java

示例3: init

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
@BeforeClass
public static void init() {
    try {
        // read log4j configuration from xml
        InputStream in = new FileInputStream(new File(TestSolrAppender.class.getResource("./log4j2.xml").getPath()));
        ConfigurationFactory factory = new XMLConfigurationFactory();
        Configuration configuration = factory
                .getConfiguration(new ConfigurationSource(in));

        // init context
        context = (LoggerContext) LogManager.getContext();
        context.start(configuration);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }   
    
}
 
开发者ID:scherziglu,项目名称:log4j,代码行数:18,代码来源:TestSolrAppender.java

示例4: 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;
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:33,代码来源:Configurator.java

示例5: 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;
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:30,代码来源:Log4jContextFactory.java

示例6: configure

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
private static void configure(final Settings settings, final Path configsPath, final Path logsPath) throws IOException, UserException {
    Objects.requireNonNull(settings);
    Objects.requireNonNull(configsPath);
    Objects.requireNonNull(logsPath);

    setLogConfigurationSystemProperty(logsPath, settings);
    // we initialize the status logger immediately otherwise Log4j will complain when we try to get the context
    configureStatusLogger();

    final LoggerContext context = (LoggerContext) LogManager.getContext(false);

    final List<AbstractConfiguration> configurations = new ArrayList<>();
    final PropertiesConfigurationFactory factory = new PropertiesConfigurationFactory();
    final Set<FileVisitOption> options = EnumSet.of(FileVisitOption.FOLLOW_LINKS);
    Files.walkFileTree(configsPath, options, Integer.MAX_VALUE, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
            if (file.getFileName().toString().equals("log4j2.properties")) {
                configurations.add((PropertiesConfiguration) factory.getConfiguration(context, file.toString(), file.toUri()));
            }
            return FileVisitResult.CONTINUE;
        }
    });

    if (configurations.isEmpty()) {
        throw new UserException(
                ExitCodes.CONFIG,
                "no log4j2.properties found; tried [" + configsPath + "] and its subdirectories");
    }

    context.start(new CompositeConfiguration(configurations));

    configureLoggerLevels(settings);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:LogConfigurator.java

示例7: loadConfiguration

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
protected void loadConfiguration(String location, LogFile logFile) {
	Assert.notNull(location, "Location must not be null");
	try {
		LoggerContext ctx = getLoggerContext();
		URL url = ResourceUtils.getURL(location);
		ConfigurationSource source = getConfigurationSource(url);
		ctx.start(ConfigurationFactory.getInstance().getConfiguration(source));
	}
	catch (Exception ex) {
		throw new IllegalStateException(
				"Could not initialize Log4J2 logging from " + location, ex);
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:14,代码来源:Log4J2LoggingSystem.java

示例8: initializeJndi

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的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

示例9: getContext

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
/**
 * Load the LoggerContext using the ContextSelector.
 * @param fqcn The fully qualified class name of the caller.
 * @param loader The ClassLoader to use or null.
 * @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.
 * @return The LoggerContext.
 */
@Override
public LoggerContext getContext(final String fqcn, final ClassLoader loader, final boolean currentContext) {
    final LoggerContext ctx = selector.getContext(fqcn, loader, currentContext);
    if (ctx.getStatus() == LoggerContext.Status.INITIALIZED) {
        ctx.start();
    }
    return ctx;
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:17,代码来源:Log4jContextFactory.java

示例10: testAdvertisementsRemovedOnConfigStop

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
@Test
public void testAdvertisementsRemovedOnConfigStop() {
    verifyExpectedEntriesAdvertised(InMemoryAdvertiser.getAdvertisedEntries());

    final LoggerContext ctx = (LoggerContext) LogManager.getContext();
    ctx.stop();

    final Map<Object, Map<String, String>> entries = InMemoryAdvertiser.getAdvertisedEntries();
    assertTrue("Entries found: " + entries, entries.isEmpty());

    //reconfigure for subsequent testing
    ctx.start();
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:14,代码来源:AdvertiserTest.java

示例11: testAdvertisementsAddedOnReconfigAfterStop

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
@Test
public void testAdvertisementsAddedOnReconfigAfterStop() {
    verifyExpectedEntriesAdvertised(InMemoryAdvertiser.getAdvertisedEntries());

    final LoggerContext ctx = (LoggerContext) LogManager.getContext();
    ctx.stop();

    final Map<Object, Map<String, String>> entries = InMemoryAdvertiser.getAdvertisedEntries();
    assertTrue("Entries found: " + entries, entries.isEmpty());

    ctx.start();

    verifyExpectedEntriesAdvertised(InMemoryAdvertiser.getAdvertisedEntries());
}
 
开发者ID:OuZhencong,项目名称:log4j2,代码行数:15,代码来源:AdvertiserTest.java

示例12: initializeJndi

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的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

示例13: testAdvertisementsRemovedOnConfigStop

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
@Test
public void testAdvertisementsRemovedOnConfigStop() {
    verifyExpectedEntriesAdvertised(InMemoryAdvertiser.getAdvertisedEntries());

    final LoggerContext ctx = LoggerContext.getContext();
    ctx.stop();

    final Map<Object, Map<String, String>> entries = InMemoryAdvertiser.getAdvertisedEntries();
    assertTrue("Entries found: " + entries, entries.isEmpty());

    //reconfigure for subsequent testing
    ctx.start();
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:14,代码来源:AdvertiserTest.java

示例14: testAdvertisementsAddedOnReconfigAfterStop

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
@Test
public void testAdvertisementsAddedOnReconfigAfterStop() {
    verifyExpectedEntriesAdvertised(InMemoryAdvertiser.getAdvertisedEntries());

    final LoggerContext ctx = LoggerContext.getContext();
    ctx.stop();

    final Map<Object, Map<String, String>> entries = InMemoryAdvertiser.getAdvertisedEntries();
    assertTrue("Entries found: " + entries, entries.isEmpty());

    ctx.start();

    verifyExpectedEntriesAdvertised(InMemoryAdvertiser.getAdvertisedEntries());
}
 
开发者ID:apache,项目名称:logging-log4j2,代码行数:15,代码来源:AdvertiserTest.java

示例15: before

import org.apache.logging.log4j.core.LoggerContext; //导入方法依赖的package包/类
@Override
protected void before() throws Throwable {
    loggerContext = (LoggerContext) LogManager.getContext(ClassLoader.getSystemClassLoader(), false, configFileUri);
    loggerContext.start();
}
 
开发者ID:vy,项目名称:log4j2-redis-appender,代码行数:6,代码来源:LoggerContextResource.java


注:本文中的org.apache.logging.log4j.core.LoggerContext.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。