本文整理汇总了Java中org.apache.logging.log4j.core.LifeCycle类的典型用法代码示例。如果您正苦于以下问题:Java LifeCycle类的具体用法?Java LifeCycle怎么用?Java LifeCycle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LifeCycle类属于org.apache.logging.log4j.core包,在下文中一共展示了LifeCycle类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testFlushAtEndOfBatch
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的package包/类
@Test
public void testFlushAtEndOfBatch() throws Exception {
final File f = new File("target", "RandomAccessFileAppenderTest.log");
// System.out.println(f.getAbsolutePath());
f.delete();
final Logger log = LogManager.getLogger("com.foo.Bar");
final String msg = "Message flushed with immediate flush=false";
log.info(msg);
((LifeCycle) LogManager.getContext()).stop(); // stop async thread
final BufferedReader reader = new BufferedReader(new FileReader(f));
final String line1 = reader.readLine();
reader.close();
f.delete();
assertNotNull("line1", line1);
assertTrue("line1 incorrect", line1.contains(msg));
final String location = "testFlushAtEndOfBatch";
assertTrue("no location", !line1.contains(location));
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:21,代码来源:RandomAccessFileAppenderTest.java
示例2: testFlushAtEndOfBatch
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的package包/类
@Test
public void testFlushAtEndOfBatch() throws Exception {
final File f = new File("target", "RollingRandomAccessFileAppenderTest.log");
// System.out.println(f.getAbsolutePath());
f.delete();
final Logger log = LogManager.getLogger("com.foo.Bar");
final String msg = "Message flushed with immediate flush=false";
log.info(msg);
((LifeCycle) LogManager.getContext()).stop(); // stop async thread
final BufferedReader reader = new BufferedReader(new FileReader(f));
final String line1 = reader.readLine();
reader.close();
f.delete();
assertNotNull("line1", line1);
assertTrue("line1 correct", line1.contains(msg));
final String location = "testFlushAtEndOfBatch";
assertTrue("no location", !line1.contains(location));
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:21,代码来源:RollingRandomAccessFileAppenderTest.java
示例3: testLocationIncluded
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的package包/类
@Test
public void testLocationIncluded() throws Exception {
final File f = new File("target", "RollingRandomAccessFileAppenderLocationTest.log");
// System.out.println(f.getAbsolutePath());
f.delete();
final Logger log = LogManager.getLogger("com.foo.Bar");
final String msg = "Message with location, flushed with immediate flush=false";
log.info(msg);
((LifeCycle) LogManager.getContext()).stop(); // stop async thread
final BufferedReader reader = new BufferedReader(new FileReader(f));
final String line1 = reader.readLine();
reader.close();
f.delete();
assertNotNull("line1", line1);
assertTrue("line1 correct", line1.contains(msg));
final String location = "testLocationIncluded";
assertTrue("has location", line1.contains(location));
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:21,代码来源:RollingRandomAccessFileAppenderLocationTest.java
示例4: testLocationIncluded
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的package包/类
@Test
public void testLocationIncluded() throws Exception {
final File f = new File("target", "RandomAccessFileAppenderLocationTest.log");
// System.out.println(f.getAbsolutePath());
f.delete();
final Logger log = LogManager.getLogger("com.foo.Bar");
final String msg = "Message with location, flushed with immediate flush=false";
log.info(msg);
((LifeCycle) LogManager.getContext()).stop(); // stop async thread
final BufferedReader reader = new BufferedReader(new FileReader(f));
final String line1 = reader.readLine();
reader.close();
f.delete();
assertNotNull("line1", line1);
assertTrue("line1 correct", line1.contains(msg));
final String location = "testLocationIncluded";
assertTrue("has location", line1.contains(location));
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:21,代码来源:RandomAccessFileAppenderLocationTest.java
示例5: testAdditivity
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的package包/类
@Test
public void testAdditivity() throws Exception {
final File f = new File("target", "AsyncLoggerConfigTest.log");
assertTrue("Deleted old file before test", !f.exists() || f.delete());
final Logger log = LogManager.getLogger("com.foo.Bar");
final String msg = "Additive logging: 2 for the price of 1!";
log.info(msg);
((LifeCycle) LogManager.getContext()).stop(); // stop async thread
final BufferedReader reader = new BufferedReader(new FileReader(f));
final String line1 = reader.readLine();
final String line2 = reader.readLine();
reader.close();
f.delete();
assertNotNull("line1", line1);
assertNotNull("line2", line2);
assertTrue("line1 correct", line1.contains(msg));
assertTrue("line2 correct", line2.contains(msg));
final String location = "testAdditivity";
assertTrue("location",
line1.contains(location) || line2.contains(location));
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:25,代码来源:AsyncLoggerConfigTest.java
示例6: testAsyncLogWritesToLog
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的package包/类
@Test
public void testAsyncLogWritesToLog() throws Exception {
final File f = new File("target", "AsyncLoggerTest.log");
// System.out.println(f.getAbsolutePath());
f.delete();
final Logger log = LogManager.getLogger("com.foo.Bar");
final String msg = "Async logger msg";
log.info(msg);
((LifeCycle) LogManager.getContext()).stop(); // stop async thread
final BufferedReader reader = new BufferedReader(new FileReader(f));
final String line1 = reader.readLine();
reader.close();
f.delete();
assertNotNull("line1", line1);
assertTrue("line1 correct", line1.contains(msg));
final String location = "testAsyncLogWritesToLog";
assertTrue("no location", !line1.contains(location));
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:21,代码来源:AsyncLoggerTest.java
示例7: testAsyncLogWritesToLog
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的package包/类
@Test
public void testAsyncLogWritesToLog() throws Exception {
final File f = new File("target", "AsyncLoggerLocationTest.log");
// System.out.println(f.getAbsolutePath());
f.delete();
final Logger log = LogManager.getLogger("com.foo.Bar");
final String msg = "Async logger msg with location";
log.info(msg);
((LifeCycle) LogManager.getContext()).stop(); // stop async thread
final BufferedReader reader = new BufferedReader(new FileReader(f));
final String line1 = reader.readLine();
reader.close();
f.delete();
assertNotNull("line1", line1);
assertTrue("line1 correct", line1.contains(msg));
final String location = "testAsyncLogWritesToLog";
assertTrue("has location", line1.contains(location));
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:21,代码来源:AsyncLoggerLocationTest.java
示例8: getContext
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的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
示例9: setTriggeringPolicy
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的package包/类
public void setTriggeringPolicy(final TriggeringPolicy triggeringPolicy) {
triggeringPolicy.initialize(this);
final TriggeringPolicy policy = this.triggeringPolicy;
int count = 0;
boolean policyUpdated = false;
do {
++count;
} while (!(policyUpdated = triggeringPolicyUpdater.compareAndSet(this, this.triggeringPolicy, triggeringPolicy))
&& count < MAX_TRIES);
if (policyUpdated) {
if (triggeringPolicy instanceof LifeCycle) {
((LifeCycle) triggeringPolicy).start();
}
if (policy instanceof LifeCycle) {
((LifeCycle) policy).stop();
}
} else {
if (triggeringPolicy instanceof LifeCycle) {
((LifeCycle) triggeringPolicy).stop();
}
}
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:23,代码来源:RollingFileManager.java
示例10: testPropertiesConfiguration
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的package包/类
@Test
public void testPropertiesConfiguration() {
final Configuration config = context.getConfiguration();
assertNotNull("No configuration created", config);
assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1);
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:18,代码来源:PropertiesConfigurationTest.java
示例11: testPropertiesConfiguration
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的package包/类
@Test
public void testPropertiesConfiguration() {
final Configuration config = context.getConfiguration();
assertNotNull("No configuration created", config);
assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1);
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 1);
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:18,代码来源:PropertiesConfigurationRootLoggerOnlyTest.java
示例12: testPropertiesConfiguration
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的package包/类
@Test
public void testPropertiesConfiguration() {
final Configuration config = context.getConfiguration();
assertNotNull("No configuration created", config);
assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 1);
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final Logger logger = LogManager.getLogger(getClass());
assertEquals("Incorrect level " + logger.getLevel(), Level.DEBUG, logger.getLevel());
logger.debug("Welcome to Log4j!");
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:21,代码来源:PropertiesConfigurationTrailingSpaceOnLevelTest.java
示例13: testPropertiesConfiguration
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的package包/类
@Test
public void testPropertiesConfiguration() {
final Configuration config = context.getConfiguration();
assertNotNull("No configuration created", config);
assertEquals("Incorrect State: " + config.getState(), config.getState(), LifeCycle.State.STARTED);
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertTrue("Incorrect number of Appenders: " + appenders.size(), appenders.size() == 3);
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertTrue("Incorrect number of LoggerConfigs: " + loggers.size(), loggers.size() == 2);
final Filter filter = config.getFilter();
assertNotNull("No Filter", filter);
assertTrue("Not a Threshold Filter", filter instanceof ThresholdFilter);
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
开发者ID:apache,项目名称:logging-log4j2,代码行数:18,代码来源:RollingFilePropertiesTest.java
示例14: stop
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的package包/类
@Override
public void stop() throws LifecycleException {
log("stopping Context");
if (!started) {
throw new LifecycleException("SimpleContext has already stopped");
}
this.lifecycle.fireLifecycleEvent(BEFORE_STOP_EVENT, null);
started = false;
if (loader != null && loader instanceof LifeCycle) {
((LifeCycle) loader).stop();
}
if (pipeline != null && pipeline instanceof LifeCycle) {
((LifeCycle) pipeline).stop();
}
Container[] children = findChildren();
for (int i = 0; i < children.length; ++i) {
if (children[i] instanceof LifeCycle) {
((Lifecycle) children[i]).stop();
}
}
this.lifecycle.fireLifecycleEvent(STOP_EVENT, null);
this.lifecycle.fireLifecycleEvent(AFTER_STOP_EVENT, null);
log("Context stopped");
}
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:29,代码来源:SimpleContext.java
示例15: onApplicationEvent
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的package包/类
@Override
public void onApplicationEvent(final ContextClosedEvent event) {
logger.info("Gracefully shutting down application.");
manager.stop();
try {
manager.tearDown();
logger.info("JOAL gracefully shut down.");
} catch (final IOException e) {
logger.error("Failed to gracefully shut down JOAL.", e);
}
// Since we disabled log4j2 shutdown hook, we need to handle it manually.
final LifeCycle loggerContext = (LoggerContext) LogManager.getContext(false);
loggerContext.stop();
}
开发者ID:anthonyraymond,项目名称:joal,代码行数:16,代码来源:ApplicationClosingListener.java
示例16: recycle
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的package包/类
public void recycle() {
if (factory != null)
factory.recycle();
JedisManager.getInstance().close();
((LifeCycle) LogManager.getContext()).stop();
}
开发者ID:eleme,项目名称:hackathon-2015,代码行数:8,代码来源:WebServer.java
示例17: close
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的package包/类
/**
* Perform whatever cleanup is required of the underlying object..
*/
@Override
public void close()
{
LifeCycle lc = ((LifeCycle)LogManager.getContext());
if (lc.isStarted())
{
lc.stop();
}
}
开发者ID:isparkes,项目名称:OpenRate,代码行数:13,代码来源:Log4JLogger.java
示例18: cleanupFilter
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的package包/类
private void cleanupFilter(final AppenderControl ctl) {
final Filter filter = ctl.getFilter();
if (filter != null) {
ctl.removeFilter(filter);
if (filter instanceof LifeCycle) {
((LifeCycle) filter).stop();
}
}
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:10,代码来源:LoggerConfig.java
示例19: start
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的package包/类
@Override
public void start() {
for (final Filter filter : filters) {
if (filter instanceof LifeCycle) {
((LifeCycle) filter).start();
}
}
isStarted = true;
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:10,代码来源:CompositeFilter.java
示例20: stop
import org.apache.logging.log4j.core.LifeCycle; //导入依赖的package包/类
@Override
public void stop() {
for (final Filter filter : filters) {
if (filter instanceof LifeCycle) {
((LifeCycle) filter).stop();
}
}
isStarted = false;
}
开发者ID:OuZhencong,项目名称:log4j2,代码行数:10,代码来源:CompositeFilter.java
注:本文中的org.apache.logging.log4j.core.LifeCycle类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论