本文整理匯總了Java中org.apache.logging.log4j.core.Logger.removeAppender方法的典型用法代碼示例。如果您正苦於以下問題:Java Logger.removeAppender方法的具體用法?Java Logger.removeAppender怎麽用?Java Logger.removeAppender使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.logging.log4j.core.Logger
的用法示例。
在下文中一共展示了Logger.removeAppender方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onDisable
import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
@Override
public void onDisable() {
//restore the old format
Appender terminalAppender = CommonLogInstaller.getTerminalAppender(TERMINAL_NAME);
Logger rootLogger = ((Logger) LogManager.getRootLogger());
ColorPluginAppender colorPluginAppender = null;
for (Appender value : rootLogger.getAppenders().values()) {
if (value instanceof ColorPluginAppender) {
colorPluginAppender = (ColorPluginAppender) value;
break;
}
}
if (colorPluginAppender != null) {
rootLogger.removeAppender(terminalAppender);
rootLogger.addAppender(colorPluginAppender.getOldAppender());
}
try {
CommonLogInstaller.setLayout(oldLayout, terminalAppender);
} catch (ReflectiveOperationException ex) {
getLogger().log(Level.WARNING, "Cannot revert log format", ex);
}
}
示例2: call
import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
public Object call() throws Exception {
// Setup for capturing logger messages
Appender mockAppender = mock(Appender.class);
when(mockAppender.getName()).thenReturn("MockAppender");
when(mockAppender.isStarted()).thenReturn(true);
when(mockAppender.isStopped()).thenReturn(false);
Logger logger = (Logger) LogManager.getLogger(ColocationLogger.class);
logger.addAppender(mockAppender);
logger.setLevel(Level.WARN);
loggingEventCaptor = ArgumentCaptor.forClass(LogEvent.class);
// Logger interval may have been hooked by the test, so adjust test delays here
int logInterval = ColocationLogger.getLogInterval();
List<LogEvent> logEvents = Collections.emptyList();
AtomicBoolean isDone = new AtomicBoolean(false);
try {
createPR(PR_REGION_NAME, true);
// Let this thread continue running long enough for the missing region to be logged a
// couple times.
// Child regions do not get created by this thread.
await().atMost(MAX_WAIT, TimeUnit.MILLISECONDS).until(() -> {
verify(mockAppender, times(numExpectedLogMessages))
.append(loggingEventCaptor.capture());
});
// createPR("region2", PR_REGION_NAME, true); // This child region is never created
} finally {
logEvents = loggingEventCaptor.getAllValues();
assertEquals(String.format("Expected %d messages to be logged, got %d.",
numExpectedLogMessages, logEvents.size()), numExpectedLogMessages,
logEvents.size());
String logMsg = logEvents.get(0).getMessage().getFormattedMessage();
logger.removeAppender(mockAppender);
numExpectedLogMessages = 1;
return logMsg;
}
}
示例3: installAppender
import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
public static void installAppender(Appender colorAppender, String terminalName) {
Logger rootLogger = (Logger) LogManager.getRootLogger();
colorAppender.start();
rootLogger.removeAppender(getTerminalAppender(terminalName));
rootLogger.addAppender(colorAppender);
}
示例4: loadLogAppender
import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
private boolean loadLogAppender()
{
Logger log = (Logger)LogManager.getRootLogger();
for(Appender appender : log.getAppenders().values())
{
if(appender instanceof RConsoleAppender)
log.removeAppender(appender);
}
mAppender = new RConsoleAppender(new DefaultConfiguration());
mAppender.start();
log.addAppender(mAppender);
return true;
}
示例5: testStructured
import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
@Test
public void testStructured() throws InterruptedException, IOException {
final Agent[] agents = new Agent[] { Agent.createAgent("localhost",
testPort) };
final FlumeAppender avroAppender = FlumeAppender.createAppender(agents,
null, "false", "Avro", null, "1000", "1000", "1", "1000",
"avro", "false", null, null, null, "ReqCtx_", null, "true",
"1", null, null, null, null);
avroAppender.start();
final Logger eventLogger = (Logger) LogManager.getLogger("EventLogger");
Assert.assertNotNull(eventLogger);
eventLogger.addAppender(avroAppender);
eventLogger.setLevel(Level.ALL);
final StructuredDataMessage msg = new StructuredDataMessage("Transfer",
"Success", "Audit");
msg.put("memo", "This is a memo");
msg.put("acct", "12345");
msg.put("amount", "100.00");
ThreadContext.put("id", UUID.randomUUID().toString());
ThreadContext.put("memo", null);
ThreadContext.put("test", "123");
EventLogger.logEvent(msg);
final Transaction transaction = channel.getTransaction();
transaction.begin();
final Event event = channel.take();
Assert.assertNotNull(event);
Assert.assertTrue("Channel contained event, but not expected message",
getBody(event).endsWith("Success"));
transaction.commit();
transaction.close();
eventSource.stop();
eventLogger.removeAppender(avroAppender);
avroAppender.stop();
}
示例6: testStructured
import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
@Test
public void testStructured() throws IOException {
final Agent[] agents = new Agent[] { Agent.createAgent("localhost",
testPort) };
final FlumeAppender avroAppender = FlumeAppender.createAppender(agents,
null, null, "false", "Avro", null, "1000", "1000", "1", "1000",
"avro", "false", null, null, null, "ReqCtx_", null, "true",
"1", null, null, null, null);
avroAppender.start();
final Logger eventLogger = (Logger) LogManager.getLogger("EventLogger");
Assert.assertNotNull(eventLogger);
eventLogger.addAppender(avroAppender);
eventLogger.setLevel(Level.ALL);
final StructuredDataMessage msg = new StructuredDataMessage("Transfer",
"Success", "Audit");
msg.put("memo", "This is a memo");
msg.put("acct", "12345");
msg.put("amount", "100.00");
ThreadContext.put("id", UUID.randomUUID().toString());
ThreadContext.put("memo", null);
ThreadContext.put("test", "123");
EventLogger.logEvent(msg);
final Transaction transaction = channel.getTransaction();
transaction.begin();
final Event event = channel.take();
Assert.assertNotNull(event);
Assert.assertTrue("Channel contained event, but not expected message", getBody(event).endsWith("Success"));
transaction.commit();
transaction.close();
eventSource.stop();
eventLogger.removeAppender(avroAppender);
avroAppender.stop();
}
示例7: close
import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
public void close() {
Logger logger = (Logger) LogManager.getLogger(this.getName());
logger.removeAppender(this);
super.clear();
}
示例8: removeAppenders
import org.apache.logging.log4j.core.Logger; //導入方法依賴的package包/類
private static void removeAppenders(final Logger root) {
final Map<String, Appender> appenders = root.getAppenders();
for (final Appender appender : appenders.values()) {
root.removeAppender(appender);
}
}