Java Code Examples for org.apache.log4j.Logger#getEffectiveLevel()

The following examples show how to use org.apache.log4j.Logger#getEffectiveLevel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Log4jHelper.java    From arthas with Apache License 2.0 6 votes vote down vote up
private static Map<String, Object> doGetLoggerInfo(Logger logger) {
    Map<String, Object> info = new HashMap<String, Object>();
    info.put(LoggerHelper.name, logger.getName());
    info.put(LoggerHelper.clazz, logger.getClass());
    CodeSource codeSource = logger.getClass().getProtectionDomain().getCodeSource();
    if (codeSource != null) {
        info.put(LoggerHelper.codeSource, codeSource.getLocation());
    }
    info.put(LoggerHelper.additivity, logger.getAdditivity());

    Level level = logger.getLevel(), effectiveLevel = logger.getEffectiveLevel();
    if (level != null) {
        info.put(LoggerHelper.level, level.toString());
    }
    if (effectiveLevel != null) {
        info.put(LoggerHelper.effectiveLevel, effectiveLevel.toString());
    }

    @SuppressWarnings("unchecked")
    List<Map<String, Object>> result = doGetLoggerAppenders(logger.getAllAppenders());
    info.put(LoggerHelper.appenders, result);
    return info;
}
 
Example 2
Source File: TestLog4jUtils.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void test() {
  Logger zk = LogManager.getLogger("org.apache.zookeeper");
  Level zkLevel = zk.getEffectiveLevel();
  Logger hbaseZk = LogManager.getLogger("org.apache.hadoop.hbase.zookeeper");
  Level hbaseZkLevel = hbaseZk.getEffectiveLevel();
  Logger client = LogManager.getLogger("org.apache.hadoop.hbase.client");
  Level clientLevel = client.getEffectiveLevel();
  Log4jUtils.disableZkAndClientLoggers();
  assertEquals(Level.OFF, zk.getLevel());
  assertEquals(Level.OFF.toString(), Log4jUtils.getEffectiveLevel(zk.getName()));
  assertEquals(Level.OFF, hbaseZk.getLevel());
  assertEquals(Level.OFF.toString(), Log4jUtils.getEffectiveLevel(hbaseZk.getName()));
  assertEquals(Level.OFF, client.getLevel());
  assertEquals(Level.OFF.toString(), Log4jUtils.getEffectiveLevel(client.getName()));
  // restore the level
  zk.setLevel(zkLevel);
  hbaseZk.setLevel(hbaseZkLevel);
  client.setLevel(clientLevel);
}
 
Example 3
Source File: LogManager.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public String getLoggerLevel(String loggerName) {

    Logger logger = Logger.getLogger(loggerName);
    if (logger == null) {
        throw new IllegalArgumentException("Logger \"" + loggerName +
                "\" does not exist");
    }
    Level level = logger.getEffectiveLevel();
    if (level == null) {
        return "";
    }
    return level.toString();
}