本文整理了Java中org.apache.logging.log4j.core.config.Configuration.getRootLogger()
方法的一些代码示例,展示了Configuration.getRootLogger()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Configuration.getRootLogger()
方法的具体详情如下:
包路径:org.apache.logging.log4j.core.config.Configuration
类名称:Configuration
方法名:getRootLogger
[英]Returns the root Logger.
[中]返回根记录器。
代码示例来源:origin: apache/hive
/**
* Stop the subordinate appender for the operation log so it will not leak a file descriptor.
* @param routingAppenderName the name of the RoutingAppender
* @param queryId the id of the query that is closing
*/
public static void stopQueryAppender(String routingAppenderName, String queryId) {
LoggerContext context = (LoggerContext) LogManager.getContext(false);
org.apache.logging.log4j.core.config.Configuration configuration = context.getConfiguration();
LoggerConfig loggerConfig = configuration.getRootLogger();
Map<String, Appender> appenders = loggerConfig.getAppenders();
RoutingAppender routingAppender = (RoutingAppender) appenders.get(routingAppenderName);
// routingAppender can be null if it has not been registered
if (routingAppender != null) {
// The appender is configured to use ${ctx:queryId} by registerRoutingAppender()
try {
Class<? extends RoutingAppender> clazz = routingAppender.getClass();
Method method = clazz.getDeclaredMethod("deleteAppender", String.class);
method.setAccessible(true);
method.invoke(routingAppender, queryId);
} catch (NoSuchMethodException | SecurityException | IllegalAccessException |
IllegalArgumentException | InvocationTargetException e) {
l4j.warn("Unable to close the operation log appender for query id " + queryId, e);
}
}
}
代码示例来源:origin: igniterealtime/Openfire
void removeAppender(final String name) {
final LoggerContext context = LoggerContext.getContext(false);
final Configuration config = context.getConfiguration();
config.getAppenders().remove( name ).stop();
for (final LoggerConfig loggerConfig : config.getLoggers().values()) {
loggerConfig.removeAppender( name );
}
config.getRootLogger().removeAppender( name );
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
static void updateLoggers(final Appender appender, final Configuration config) {
final Level level = null;
final Filter filter = null;
for (final LoggerConfig loggerConfig : config.getLoggers().values()) {
loggerConfig.addAppender(appender, level, filter);
}
config.getRootLogger().addAppender(appender, level, filter);
}
代码示例来源: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: igniterealtime/Openfire
String addAppender(final Writer writer) {
final String name = "openfire-s2s-test-appender-" + StringUtils.randomString( 10 );
final LoggerContext context = LoggerContext.getContext(false);
final Configuration config = context.getConfiguration();
final PatternLayout layout = PatternLayout.createDefaultLayout(config);
final Appender appender = WriterAppender.createAppender(layout, null, writer, name, false, true);
appender.start();
config.addAppender(appender);
final Level level = null;
final Filter filter = null;
for (final LoggerConfig loggerConfig : config.getLoggers().values()) {
loggerConfig.addAppender(appender, level, filter);
}
config.getRootLogger().addAppender(appender, level, filter);
return name;
}
代码示例来源: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: apache/hive
null);
LoggerConfig loggerConfig = configuration.getRootLogger();
loggerConfig.addAppender(routingAppender, null, null);
context.updateLoggers();
代码示例来源:origin: apache/ignite
/**
* Creates console appender with some reasonable default logging settings.
*
* @return Logger with auto configured console appender.
*/
public Logger createConsoleLogger() {
// from http://logging.apache.org/log4j/2.x/manual/customconfig.html
final LoggerContext ctx = impl.getContext();
final Configuration cfg = ctx.getConfiguration();
PatternLayout.Builder builder = PatternLayout.newBuilder()
.withPattern("%d{ISO8601}][%-5p][%t][%c{1}] %m%n")
.withCharset(Charset.defaultCharset())
.withAlwaysWriteExceptions(false)
.withNoConsoleNoAnsi(false);
PatternLayout layout = builder.build();
ConsoleAppender.Builder consoleAppenderBuilder = ConsoleAppender.newBuilder()
.withName(CONSOLE_APPENDER)
.withLayout(layout);
ConsoleAppender consoleApp = consoleAppenderBuilder.build();
consoleApp.start();
cfg.addAppender(consoleApp);
cfg.getRootLogger().addAppender(consoleApp, Level.TRACE, null);
ctx.updateLoggers(cfg);
return ctx.getRootLogger();
}
代码示例来源:origin: apache/hive
null);
LoggerConfig loggerConfig = configuration.getRootLogger();
loggerConfig.addAppender(routingAppender, null, null);
context.updateLoggers();
代码示例来源:origin: mulesoft/mule
private LoggerConfig getRootLogger(LoggerContext context) {
return context.getConfiguration().getRootLogger();
}
代码示例来源:origin: mulesoft/mule
@Test
public void perAppDefaultAppender() throws Exception {
when(context.isArtifactClassloader()).thenReturn(true);
when(context.getArtifactDescriptor().getDeploymentProperties()).thenReturn(empty());
contextConfigurer.update(context);
ArgumentCaptor<RollingFileAppender> appenderCaptor = ArgumentCaptor.forClass(RollingFileAppender.class);
verify(context.getConfiguration()).addAppender(appenderCaptor.capture());
Appender perAppAppender = appenderCaptor.getValue();
assertThat(perAppAppender, notNullValue());
assertThat(perAppAppender.getName(), equalTo(PER_APP_FILE_APPENDER_NAME));
assertThat(perAppAppender.isStarted(), is(true));
String filePattern = ClassUtils.getFieldValue(perAppAppender, FILE_PATTERN_PROPERTY, true);
String filePatternTemplate = filePattern.substring(filePattern.lastIndexOf('/') + 1);
String filePatternTemplateDateSuffix = filePatternTemplate.substring(filePatternTemplate.lastIndexOf('.') + 1);
assertThat(filePatternTemplateDateSuffix, equalTo(FILE_PATTERN_TEMPLATE_DATE_SECTION));
LoggerConfig rootLogger = context.getConfiguration().getRootLogger();
verify(rootLogger).addAppender(perAppAppender, Level.ALL, null);
}
代码示例来源:origin: ops4j/org.ops4j.pax.logging
@Override
public void beforeStopConfiguration(final Configuration configuration) {
// only sleep once per configuration stop
if (loggerConfig == configuration.getRootLogger()) {
try {
Thread.sleep(SLEEP_MILLIS);
} catch (final InterruptedException e) {
StatusLogger.getLogger().warn("Sleep before stop configuration was interrupted.");
}
}
}
代码示例来源:origin: ldbc/ldbc_graphalytics
public static void appendFileLogger(Level level, String name, Path filePath) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
Layout layout = PatternLayout.createLayout("%d{HH:mm} [%-5p] %msg%n", null, config, null, null, true, false, null, null);
Appender appender = FileAppender.createAppender(filePath.toFile().getAbsolutePath(), "true", "false", name, "true",
"false", "false", "8192", layout, null, "false", null, config);
appender.start();
config.getRootLogger().addAppender(appender, level, null);
ctx.updateLoggers();
}
代码示例来源:origin: org.apache.pulsar/pulsar-functions-instance
private void addLogTopicHandler() {
if (logAppender == null) return;
LoggerContext context = LoggerContext.getContext(false);
Configuration config = context.getConfiguration();
config.addAppender(logAppender);
for (final LoggerConfig loggerConfig : config.getLoggers().values()) {
loggerConfig.addAppender(logAppender, null, null);
}
config.getRootLogger().addAppender(logAppender, null, null);
}
代码示例来源:origin: org.apache.pulsar/pulsar-functions-instance
private void removeLogTopicHandler() {
if (logAppender == null) return;
LoggerContext context = LoggerContext.getContext(false);
Configuration config = context.getConfiguration();
for (final LoggerConfig loggerConfig : config.getLoggers().values()) {
loggerConfig.removeAppender(logAppender.getName());
}
config.getRootLogger().removeAppender(logAppender.getName());
}
代码示例来源:origin: ldbc/ldbc_graphalytics
public static void appendSimplifiedConsoleLogger(Level level) {
final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
Layout layout = PatternLayout.createLayout("%msg%n", null, config, null, null, true, false, null, null);
Appender appender = ConsoleAppender.createAppender(layout, null, ConsoleAppender.Target.SYSTEM_OUT, "stdout", true, true);
appender.start();
config.getRootLogger().addAppender(appender, level, null);
ctx.updateLoggers();
}
代码示例来源:origin: apache/asterixdb
public static void start() {
final LoggerContext context = LoggerContext.getContext(false);
final Appender appender = WriterAppender.createAppender(null, null, new LogWriter(), "MEMORY", false, true);
appender.start();
final Configuration config = context.getConfiguration();
config.addAppender(appender);
for (final LoggerConfig loggerConfig : config.getLoggers().values()) {
loggerConfig.addAppender(appender, null, null);
}
config.getRootLogger().addAppender(appender, Level.ALL, null);
context.updateLoggers();
}
代码示例来源:origin: FINRAOS/herd
@Override
public void removeLoggingAppender(String appenderName)
{
// Get the configuration and remove the appender from it.
final LoggerContext loggerContext = (LoggerContext) LogManager.getContext(false);
final Configuration configuration = loggerContext.getConfiguration();
configuration.getRootLogger().removeAppender(appenderName);
}
代码示例来源:origin: undera/jmeter-plugins
public void configure() {
PatternLayout.Builder patternBuilder = PatternLayout.newBuilder();
patternBuilder.withPattern("%d %p %c{1.}: %m%n");
PatternLayout layout = patternBuilder.build();
ConsoleAppender consoleAppender = ConsoleAppender.createDefaultAppenderForLayout(layout);
consoleAppender.start();
Configuration configuration = ((LoggerContext) LogManager.getContext(false)).getConfiguration();
LoggerConfig rootLogger = configuration.getRootLogger();
rootLogger.setLevel(Level.INFO);
rootLogger.addAppender(consoleAppender, Level.INFO, null);
}
}
代码示例来源:origin: kg.apc/jmeter-plugins-cmn-jmeter
public void configure() {
PatternLayout.Builder patternBuilder = PatternLayout.newBuilder();
patternBuilder.withPattern("%d %p %c{1.}: %m%n");
PatternLayout layout = patternBuilder.build();
ConsoleAppender consoleAppender = ConsoleAppender.createDefaultAppenderForLayout(layout);
consoleAppender.start();
Configuration configuration = ((LoggerContext) LogManager.getContext(false)).getConfiguration();
LoggerConfig rootLogger = configuration.getRootLogger();
rootLogger.setLevel(Level.INFO);
rootLogger.addAppender(consoleAppender, Level.INFO, null);
}
}
内容来源于网络,如有侵权,请联系作者删除!