本文整理匯總了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);
}
}
示例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");
}
示例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();
}
}
示例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;
}
示例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;
}
示例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);
}
示例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() + "].");
}
示例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;
}
示例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();
}
示例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());
}
示例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());
}
示例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();
}
示例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());
}
示例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();
}