org.apache.logging.log4j.LogManager.getRootLogger()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(210)

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

LogManager.getRootLogger介绍

[英]Returns the root logger.
[中]返回根记录器。

代码示例

代码示例来源:origin: apache/ignite

@Override public Logger apply(Boolean init) {
    if (init)
      Configurator.initialize(LogManager.ROOT_LOGGER_NAME, cfgUrl.toString());
    return (Logger)LogManager.getRootLogger();
  }
});

代码示例来源:origin: apache/ignite

@Override public Logger apply(Boolean init) {
    if (init)
      Configurator.initialize(LogManager.ROOT_LOGGER_NAME, cfgUrl.toString());
    return (Logger)LogManager.getRootLogger();
  }
});

代码示例来源:origin: apache/ignite

@Override public Logger apply(Boolean init) {
    if (init)
      Configurator.initialize(LogManager.ROOT_LOGGER_NAME, path);
    return (Logger)LogManager.getRootLogger();
  }
});

代码示例来源:origin: apache/ignite

@Override public Logger apply(Boolean init) {
    if (init)
      ctx.reconfigure();
    return (Logger)LogManager.getRootLogger();
  }
});

代码示例来源:origin: apache/geode

private static LoggerContext getRootLoggerContext() {
 return ((Logger) LogManager.getRootLogger()).getContext();
}

代码示例来源:origin: apache/ignite

/**
 * Gets {@link IgniteLogger} wrapper around log4j logger for the given
 * category. If category is {@code null}, then root logger is returned. If
 * category is an instance of {@link Class} then {@code (Class)ctgr).getName()}
 * is used as category name.
 *
 * @param ctgr {@inheritDoc}
 * @return {@link IgniteLogger} wrapper around log4j logger.
 */
@Override public Log4J2Logger getLogger(Object ctgr) {
  if (ctgr == null)
    return new Log4J2Logger((Logger)LogManager.getRootLogger(), cfg);
  if (ctgr instanceof Class) {
    String name = ((Class<?>)ctgr).getName();
    return new Log4J2Logger((Logger)LogManager.getLogger(name), cfg);
  }
  String name = ctgr.toString();
  return new Log4J2Logger((Logger)LogManager.getLogger(name), cfg);
}

代码示例来源:origin: apache/drill

public void localJobDebugger(int exitVal, String taskId) {
 StringBuilder sb = new StringBuilder();
 sb.append("\n");
 sb.append("Task failed!\n");
 sb.append("Task ID:\n  " + taskId + "\n\n");
 sb.append("Logs:\n");
 console.printError(sb.toString());
 for (Appender appender : ((Logger) LogManager.getRootLogger()).getAppenders().values()) {
  if (appender instanceof FileAppender) {
   console.printError(((FileAppender) appender).getFileName());
  } else if (appender instanceof RollingFileAppender) {
   console.printError(((RollingFileAppender) appender).getFileName());
  }
 }
}

代码示例来源:origin: blynkkk/blynk-server

/**
 * Sets desired log level from properties.
 *
 * @param level - desired log level. error|info|debug|trace, etc.
 */
private static void changeLogLevel(String level) {
  Level newLevel = Level.valueOf(level);
  Configurator.setAllLevels(LogManager.getRootLogger().getName(), newLevel);
}

代码示例来源:origin: apache/hive

/**
 * Get path of the log file for user to see on the WebUI.
 */
public static String getLogFilePath() {
 String logFilePath = null;
 org.apache.logging.log4j.Logger rootLogger = LogManager.getRootLogger();
 if (rootLogger instanceof org.apache.logging.log4j.core.Logger) {
  org.apache.logging.log4j.core.Logger coreLogger =
    (org.apache.logging.log4j.core.Logger)rootLogger;
  for (Appender appender : coreLogger.getAppenders().values()) {
   if (appender instanceof FileAppender) {
    logFilePath = ((FileAppender) appender).getFileName();
   } else if (appender instanceof RollingFileAppender) {
    logFilePath = ((RollingFileAppender) appender).getFileName();
   } else if (appender instanceof RollingRandomAccessFileAppender) {
    logFilePath = ((RollingRandomAccessFileAppender) appender).getFileName();
   }
  }
 }
 return logFilePath;
}

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

@Parameters
public static Collection<Object[]> data() {
  return Arrays.asList(new Object[][] {
      { new LoggerContext("").getLogger("", null) },
      { LogManager.getRootLogger() },
      { LogManager.getLogger() },
      { LogManager.getLogger("test") } });
}

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

@Test
public void getRootLogger() {
  assertNotNull(LogManager.getRootLogger());
  assertNotNull(LogManager.getLogger(Strings.EMPTY));
  assertNotNull(LogManager.getLogger(LogManager.ROOT_LOGGER_NAME));
  assertEquals(LogManager.getRootLogger(), LogManager.getLogger(Strings.EMPTY));
  assertEquals(LogManager.getRootLogger(), LogManager.getLogger(LogManager.ROOT_LOGGER_NAME));
}

代码示例来源:origin: apache/drill

for (Appender appender : ((Logger) LogManager.getRootLogger()).getAppenders().values()) {
 if (appender instanceof FileAppender) {
  console.printInfo("Execution log at: " + ((FileAppender) appender).getFileName());

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

@Test
  public void testLayoutTab() throws Exception {
    final Logger root = (Logger) LogManager.getRootLogger();
    CsvParameterLayoutTest.testLayoutNormalApi(root, CsvParameterLayout.createLayout(CSVFormat.TDF), true);
  }
}

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

@Test
public void testLayoutDefaultObjectArrayMessage() throws Exception {
  final Logger root = (Logger) LogManager.getRootLogger();
  CsvParameterLayoutTest.testLayoutNormalApi(root, CsvParameterLayout.createDefaultLayout(), true);
}

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

@Test
public void testLayoutDefaultNormal() throws Exception {
  final Logger root = (Logger) LogManager.getRootLogger();
  CsvParameterLayoutTest.testLayoutNormalApi(root, CsvParameterLayout.createDefaultLayout(), false);
}

代码示例来源:origin: apache/hive

@Test
public void testStringAppender() throws Exception {
 // Get the RootLogger which, if you don't have log4j2-test.properties defined, will only log ERRORs
 Logger logger = LogManager.getRootLogger();
 // Create a String Appender to capture log output
 StringAppender appender = StringAppender.createStringAppender("%m");
 appender.addToLogger(logger.getName(), Level.INFO);
 appender.start();
 // Logger to the string appender
 logger.info("Hello!");
 logger.info(" World");
 assertEquals("Hello! World", appender.getOutput());
 appender.removeFromLogger(LogManager.getRootLogger().getName());
}

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

@Test
public void testLogJsonArgument() throws InterruptedException {
  final ListAppender appender = (ListAppender) init.getAppender("List");
  appender.countDownLatch = new CountDownLatch(4);
  appender.clear();
  final Logger logger = (Logger) LogManager.getRootLogger();
  final String json = "{\"id\":10,\"name\":\"Alice\"}";
  logger.error("log:{}", json);
  // wait until background thread finished processing
  final int msgCount = 1;
  if (appender.getMessages().size() < msgCount) {
    appender.countDownLatch.await(5, TimeUnit.SECONDS);
  }
  assertEquals("Background thread did not finish processing: msg count", msgCount, appender.getMessages().size());
  // don't stop appender until background thread is done
  appender.stop();
  final List<String> list = appender.getMessages();
  final String eventStr = list.get(0).toString();
  Assert.assertTrue(eventStr, eventStr.contains(json));
}

代码示例来源:origin: apache/hive

@Test
 public void testHiveEventCounterAppender() throws Exception {
  Logger logger = LogManager.getRootLogger();
  HiveEventCounter appender = HiveEventCounter.createInstance("EventCounter", true, null, null);
  appender.addToLogger(logger.getName(), Level.INFO);
  appender.start();

  logger.info("Test");
  logger.info("Test");
  logger.info("Test");
  logger.info("Test");

  logger.error("Test");
  logger.error("Test");
  logger.error("Test");

  logger.warn("Test");
  logger.warn("Test");

  logger.fatal("Test");

  assertEquals(4, appender.getInfo());
  assertEquals(3, appender.getError());
  assertEquals(2, appender.getWarn());
  assertEquals(1, appender.getFatal());
  appender.removeFromLogger(LogManager.getRootLogger().getName());
 }
}

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

void register() {
  if (LogManager.getContext(false) instanceof LoggerContext) {
    final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    if (ctx.getConfiguration() instanceof AbstractConfiguration) {
      final AbstractConfiguration config = (AbstractConfiguration) ctx.getConfiguration();
      final Appender appender = getSingleton();
      appender.start();
      config.addAppender(appender);
      final Logger rootLogger = LogManager.getRootLogger();
      final LoggerConfig loggerConfig = config.getLoggerConfig(rootLogger.getName());
      loggerConfig.addAppender(appender, null, null);
      ctx.updateLoggers();
    }
  }
}

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

void deregister() {
  if (LogManager.getContext(false) instanceof LoggerContext) {
    final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
    if (ctx.getConfiguration() instanceof AbstractConfiguration) {
      final AbstractConfiguration config = (AbstractConfiguration) ctx.getConfiguration();
      final Appender appender = getSingleton();
      appender.stop();
      config.removeAppender(appender.getName());
      final Logger rootLogger = LogManager.getRootLogger();
      final LoggerConfig loggerConfig = config.getLoggerConfig(rootLogger.getName());
      loggerConfig.removeAppender(appender.getName());
      ctx.updateLoggers();
    }
  }
}

相关文章