热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

org.apache.logging.log4j.core.Logger.setLevel()方法的使用及代码示例

本文整理了Java中org.apache.logging.log4j.core.Logger.setLevel()方法的一些代码示例,展示了Logger.s

本文整理了Java中org.apache.logging.log4j.core.Logger.setLevel()方法的一些代码示例,展示了Logger.setLevel()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Logger.setLevel()方法的具体详情如下:
包路径:org.apache.logging.log4j.core.Logger
类名称:Logger
方法名:setLevel

Logger.setLevel介绍

[英]This method is not exposed through the public API and is provided primarily for unit testing.

If the new level is null, this logger inherits the level from its parent.
[中]此方法不通过公共API公开,主要用于单元测试。
如果新级别为null,则此记录器将从其父级继承该级别。

代码示例

代码示例来源:origin: wildfly/wildfly

@Override
public void setLevel(String level) {
Level new_level=strToLevel(level);
if(new_level == null)
return;
if(logger instanceof org.apache.logging.log4j.core.Logger)
((org.apache.logging.log4j.core.Logger)logger).setLevel(new_level);
else if(logger instanceof SimpleLogger)
((SimpleLogger)logger).setLevel(new_level);
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

protected void initRootLogger(final Appender appender) {
root.addAppender(appender);
root.setAdditive(false);
root.setLevel(Level.DEBUG);
}

代码示例来源:origin: alibaba/nacos

@Override
public void setLevel(Level level) {
this.level = level;
org.apache.logging.log4j.Level l = org.apache.logging.log4j.Level.toLevel(level.getName(),
org.apache.logging.log4j.Level.ERROR);
logger.setLevel(l);
logger.getContext().getConfiguration().getLoggerConfig(this.logger.getName()).setLevel(l);
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

root.setLevel(Level.DEBUG);

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testSubstituteStructuredData() {
final String mdcId = "RequestContext";
final String expectedToCOntain= String.format("ATM %s MSG-ID - Message", PROCESSID);
for (final Appender appender : root.getAppenders().values()) {
root.removeAppender(appender);
}
final AbstractStringLayout layout = Rfc5424Layout.createLayout(Facility.LOCAL0, "Event", 3692, false, mdcId,
null, null, true, null, "ATM", "MSG-ID", "key1, key2, locale", null, null, null, false, null, null);
final ListAppender appender = new ListAppender("List", null, layout, true, false);
appender.start();
root.addAppender(appender);
root.setLevel(Level.DEBUG);
root.info("Message");
try {
final List list = appender.getMessages();
assertTrue("Not enough list entries", list.size() > 0);
final String message = list.get(0);
Assert.assertTrue("Not the expected message received", message.contains(expectedToContain));
appender.clear();
} finally {
root.removeAppender(appender);
appender.stop();
}
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

root.setLevel(Level.DEBUG);

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testParameterizedMessage() {
for (final Appender appender : root.getAppenders().values()) {
root.removeAppender(appender);
}
// set up appender
final AbstractStringLayout layout = Rfc5424Layout.createLayout(Facility.LOCAL0, "Event", 3692, true, "RequestContext",
null, null, true, null, "ATM", null, "key1, key2, locale", null, null, null, true, null, null);
final ListAppender appender = new ListAppender("List", null, layout, true, false);
appender.start();
// set appender on root and set level to debug
root.addAppender(appender);
root.setLevel(Level.DEBUG);
root.info("Hello {}", "World");
try {
final List list = appender.getMessages();
assertTrue("Not enough list entries", list.size() > 0);
final String message = list.get(0);
assertTrue("Incorrect message. Expected - Hello World, Actual - " + message, message.contains("Hello World"));
} finally {
root.removeAppender(appender);
appender.stop();
}
}
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

/**
* Test case for MDC exception conversion pattern.
*/
@Test
public void testException() throws Exception {
for (final Appender appender : root.getAppenders().values()) {
root.removeAppender(appender);
}
// set up layout/appender
final AbstractStringLayout layout = Rfc5424Layout.createLayout(Facility.LOCAL0, "Event", 3692, true, "RequestContext",
null, null, true, null, "ATM", null, "key1, key2, locale", null, "loginId", "%xEx", true, null, null);
final ListAppender appender = new ListAppender("List", null, layout, true, false);
appender.start();
// set appender on root and set level to debug
root.addAppender(appender);
root.setLevel(Level.DEBUG);
ThreadContext.put("loginId", "JohnDoe");
// output starting message
root.debug("starting mdc pattern test", new IllegalArgumentException("Test"));
try {
final List list = appender.getMessages();
assertTrue("Not enough list entries", list.size() > 1);
final String string = list.get(1);
assertTrue("No Exception in " + string, string.contains("IllegalArgumentException"));
appender.clear();
} finally {
root.removeAppender(appender);
appender.stop();
}
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

root.setLevel(Level.DEBUG);

代码示例来源:origin: org.apache.logging.log4j/log4j-core

root.addAppender(appender);
root.setAdditive(false);
root.setLevel(Level.DEBUG);

代码示例来源:origin: org.apache.logging.log4j/log4j-core

root.setLevel(Level.DEBUG);

代码示例来源:origin: org.apache.logging.log4j/log4j-core

root.setLevel(Level.DEBUG);

代码示例来源:origin: org.apache.logging.log4j/log4j-core

root.setLevel(Level.DEBUG);

代码示例来源:origin: org.apache.logging.log4j/log4j-core

this.rootLogger.setLevel(Level.DEBUG);

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testUdpAppender() throws Exception {
try {
udpServer.latch.await();
} catch (final InterruptedException ex) {
ex.printStackTrace();
}
// @formatter:off
final SocketAppender appender = SocketAppender.newBuilder()
.withProtocol(Protocol.UDP)
.withPort(tcpServer.getLocalPort())
.withReconnectDelayMillis(-1)
.withName("test")
.withImmediateFail(false)
.withLayout(JsonLayout.newBuilder().setProperties(true).build())
.build();
// @formatter:on
appender.start();
// set appender on root and set level to debug
logger.addAppender(appender);
logger.setAdditive(false);
logger.setLevel(Level.DEBUG);
logger.debug("This is a udp message");
final LogEvent event = udpServer.getQueue().poll(3, TimeUnit.SECONDS);
assertNotNull("No event retrieved", event);
assertTrue("Incorrect event", event.getMessage().getFormattedMessage().equals("This is a udp message"));
assertTrue("Message not delivered via UDP", udpServer.getCount() > 0);
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

this.rootLogger.setLevel(Level.DEBUG);

代码示例来源:origin: org.apache.logging.log4j/log4j-core

this.rootLogger.setLevel(Level.DEBUG);

代码示例来源:origin: org.apache.logging.log4j/log4j-core

this.rootLogger.setLevel(Level.DEBUG);

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testTcpAppenderDeadlock() throws Exception {
// @formatter:off
final SocketAppender appender = SocketAppender.newBuilder()
.withHost("localhost")
.withPort(DYN_PORT)
.withReconnectDelayMillis(100)
.withName("test")
.withImmediateFail(false)
.withLayout(JsonLayout.newBuilder().setProperties(true).build())
.build();
// @formatter:on
appender.start();
// set appender on root and set level to debug
logger.addAppender(appender);
logger.setAdditive(false);
logger.setLevel(Level.DEBUG);
final TcpSocketTestServer tcpSocketServer = new TcpSocketTestServer(DYN_PORT);
try {
tcpSocketServer.start();
logger.debug("This message is written because a deadlock never.");
final LogEvent event = tcpSocketServer.getQueue().poll(3, TimeUnit.SECONDS);
assertNotNull("No event retrieved", event);
} finally {
tcpSocketServer.shutdown();
}
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testTcpAppenderNoWait() throws Exception {
// @formatter:off
final SocketAppender appender = SocketAppender.newBuilder()
.withHost("localhost")
.withPort(ERROR_PORT)
.withReconnectDelayMillis(100)
.withName("test")
.withImmediateFail(false)
.withIgnoreExceptions(false)
.withLayout(JsonLayout.newBuilder().setProperties(true).build())
.build();
// @formatter:on
appender.start();
// set appender on root and set level to debug
logger.addAppender(appender);
logger.setAdditive(false);
logger.setLevel(Level.DEBUG);
try {
logger.debug("This message is written because a deadlock never.");
fail("No Exception was thrown");
} catch (final Exception ex) {
// TODO: move exception to @Test(expect = Exception.class)
// Failure is expected.
// ex.printStackTrace();
}
}

推荐阅读
author-avatar
拍友2502906483
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有