本文整理了Java中org.apache.logging.log4j.core.config.Configuration.getLoggerConfig()
方法的一些代码示例,展示了Configuration.getLoggerConfig()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.getLoggerConfig()
方法的具体详情如下:
包路径:org.apache.logging.log4j.core.config.Configuration
类名称:Configuration
方法名:getLoggerConfig
[英]Locates the appropriate LoggerConfig for a Logger name. This will remove tokens from the package name as necessary or return the root LoggerConfig if no other matches were found.
[中]查找记录器名称的相应LoggerConfig。这将根据需要从包名称中删除标记,或者如果没有找到其他匹配项,则返回根LoggerConfig。
代码示例来源:origin: apache/hive
@VisibleForTesting
public void addToLogger(String loggerName, Level level) {
LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerName);
loggerConfig.addAppender(this, level, null);
context.updateLoggers();
}
代码示例来源:origin: Graylog2/graylog2-server
private void initializeLogging(final Level logLevel) {
final LoggerContext context = (LoggerContext) LogManager.getContext(false);
final org.apache.logging.log4j.core.config.Configuration config = context.getConfiguration();
config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME).setLevel(logLevel);
config.getLoggerConfig(Main.class.getPackage().getName()).setLevel(logLevel);
context.updateLoggers(config);
}
代码示例来源:origin: apache/hive
@VisibleForTesting
public void removeFromLogger(String loggerName) {
LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerName);
loggerConfig.removeAppender(APPENDER_NAME);
context.updateLoggers();
}
代码示例来源:origin: Graylog2/graylog2-server
@VisibleForTesting
protected Level getLoggerLevel(final String loggerName) {
final LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
final Configuration configuration = loggerContext.getConfiguration();
final LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerName);
return loggerConfig.getLevel();
}
代码示例来源:origin: apache/hive
public void addToLogger(String loggerName, Level level) {
LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerName);
loggerConfig.addAppender(this, level, null);
context.updateLoggers();
}
代码示例来源:origin: apache/storm
public void setLoggerLevel(LoggerContext logContext, String loggerName, String newLevelStr) {
Level newLevel = Level.getLevel(newLevelStr);
Configuration configuration = logContext.getConfiguration();
LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerName);
if (loggerConfig.getName().equalsIgnoreCase(loggerName)) {
LOG.info("Setting {} log level to: {}", loggerConfig, newLevel);
loggerConfig.setLevel(newLevel);
} else {
// create a new config. Make it additive (true) s.t. inherit parents appenders
LoggerConfig newLoggerConfig = new LoggerConfig(loggerName, newLevel, true);
LOG.info("Adding config for: {} with level: {}", newLoggerConfig, newLevel);
configuration.addLogger(loggerName, newLoggerConfig);
}
}
}
代码示例来源:origin: apache/hive
@VisibleForTesting
public void removeFromLogger(String loggerName) {
LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerName);
loggerConfig.removeAppender(APPENDER_NAME);
context.updateLoggers();
}
代码示例来源:origin: apache/hive
@VisibleForTesting
public void addToLogger(String loggerName, Level level) {
LoggerConfig loggerConfig = configuration.getLoggerConfig(loggerName);
loggerConfig.addAppender(this, level, null);
context.updateLoggers();
}
代码示例来源:origin: Graylog2/graylog2-server
@VisibleForTesting
protected void setLoggerLevel(final String loggerName, final Level level) {
final LoggerContext context = (LoggerContext) LogManager.getContext(false);
final Configuration config = context.getConfiguration();
final LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
if(loggerName.equals(loggerConfig.getName())) {
loggerConfig.setLevel(level);
} else {
final LoggerConfig newLoggerConfig = new LoggerConfig(loggerName, level, loggerConfig.isAdditive());
newLoggerConfig.setLevel(level);
config.addLogger(loggerName, newLoggerConfig);
}
context.updateLoggers();
}
代码示例来源:origin: Graylog2/graylog2-server
private void addInstrumentedAppender(final MetricRegistry metrics, final Level level) {
final InstrumentedAppender appender = new InstrumentedAppender(metrics, null, null, false);
appender.start();
final LoggerContext context = (LoggerContext) LogManager.getContext(false);
final org.apache.logging.log4j.core.config.Configuration config = context.getConfiguration();
config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME).addAppender(appender, level, null);
context.updateLoggers(config);
}
代码示例来源: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
@Test(expected = NullPointerException.class)
public void testGetLoggerConfigNull() throws Exception {
final Configuration config = this.ctx.getConfiguration();
assertEquals(config.getRootLogger(), config.getLoggerConfig(null));
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Test
public void testGetLoggerConfigEmpty() throws Exception {
final Configuration config = this.ctx.getConfiguration();
assertEquals(config.getRootLogger(), config.getLoggerConfig(Strings.EMPTY));
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Test
public void testInheritParentDefaultLevel() throws IOException {
Configuration configuration = loadConfiguration(prefix + "default-level.xml");
try {
assertEquals(Level.ERROR, configuration.getLoggerConfig("com.foo").getLevel());
} finally {
configuration.stop();
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Test
public void testInheritParentLevel() throws IOException {
Configuration configuration = loadConfiguration(prefix + "inherit-level.xml");
try {
assertEquals(Level.TRACE, configuration.getLoggerConfig("com.foo").getLevel());
} finally {
configuration.stop();
}
}
代码示例来源:origin: apache/hive
@Before
public void setup() {
// programmatically set root logger level to INFO. By default if log4j2-test.properties is not
// available root logger will use ERROR log level
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration config = ctx.getConfiguration();
LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
loggerConfig.setLevel(Level.INFO);
ctx.updateLoggers();
}
代码示例来源:origin: apache/hive
public TestTxnHandler() throws Exception {
TxnDbUtil.setConfValues(conf);
LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
Configuration conf = ctx.getConfiguration();
conf.getLoggerConfig(CLASS_NAME).setLevel(Level.DEBUG);
ctx.updateLoggers(conf);
tearDown();
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Test
public void testBadFilterParam() throws Exception {
ctx = Configurator.initialize("Test1", "bad/log4j-badfilterparam.xml");
LogManager.getLogger("org.apache.test.TestConfigurator");
final Configuration config = ctx.getConfiguration();
assertNotNull("No configuration", config);
assertEquals("Unexpected Configuration", "XMLConfigTest", config.getName());
final LoggerConfig lcfg = config.getLoggerConfig("org.apache.logging.log4j.test1");
assertNotNull("No Logger", lcfg);
final Filter filter = lcfg.getFilter();
assertNull("Unexpected Filter", filter);
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Test
public void testBadStatus() throws Exception {
ctx = Configurator.initialize("Test1", "bad/log4j-status.xml");
LogManager.getLogger("org.apache.test.TestConfigurator");
final Configuration config = ctx.getConfiguration();
assertNotNull("No configuration", config);
assertEquals("Unexpected Configuration", "XMLConfigTest", config.getName());
final LoggerConfig root = config.getLoggerConfig("");
assertNotNull("No Root Logger", root);
assertTrue("Expected error level, was " + root.getLevel(), Level.ERROR == root.getLevel());
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
@Test
public void testLevelInheritence() throws Exception {
final Configuration config = context.getConfiguration();
final LoggerConfig loggerConfig = config.getLoggerConfig("org.apache.logging.log4j.core.LoggerTest");
assertNotNull(loggerConfig);
assertEquals(loggerConfig.getName(), "org.apache.logging.log4j.core.LoggerTest");
assertEquals(loggerConfig.getLevel(), Level.DEBUG);
final Logger localLogger = context.getLogger("org.apache.logging.log4j.core.LoggerTest");
assertTrue("Incorrect level - expected DEBUG, actual " + localLogger.getLevel(), localLogger.getLevel() == Level.DEBUG);
}
内容来源于网络,如有侵权,请联系作者删除!