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

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

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

LogManager.getLogger介绍

[英]Retrieve the appropriate Logger instance.
[中]检索适当的记录器实例。

代码示例

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

/**
* @deprecated Make sure to use {@link Logger#getLogger(String)} instead.
*/
public
static
Category getInstance(String name) {
 return LogManager.getLogger(name);
}

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

/**
* @deprecated Please make sure to use {@link Logger#getLogger(Class)} instead.
*/ 
public
static
Category getInstance(Class clazz) {
 return LogManager.getLogger(clazz);
}

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

/**
  Like {@link #getLogger(String)} except that the type of logger
  instantiated depends on the type returned by the {@link
  LoggerFactory#makeNewLoggerInstance} method of the
  <code>factory</code> parameter.
  <p>This method is intended to be used by sub-classes.
  @param name The name of the logger to retrieve.
  @param factory A {@link LoggerFactory} implementation that will
  actually create a new Instance.
  @since 0.8.5 */
public
static
Logger getLogger(String name, LoggerFactory factory) {
 return LogManager.getLogger(name, factory);
}

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

/**
 * Retrieve a logger named according to the value of the
 * <code>name</code> parameter. If the named logger already exists,
 * then the existing instance will be returned. Otherwise, a new
 * instance is created.  
 *
 * <p>By default, loggers do not have a set level but inherit it
 * from their neareast ancestor with a set level. This is one of the
 * central features of log4j.
 *
 * @param name The name of the logger to retrieve.  
*/
static
public
Logger getLogger(String name) {
 return LogManager.getLogger(name);
}

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

/**
 * Shorthand for <code>getLogger(clazz.getName())</code>.
 *
 * @param clazz The name of <code>clazz</code> will be used as the
 * name of the logger to retrieve.  See {@link #getLogger(String)}
 * for more detailed information.
 */
static
public
Logger getLogger(Class clazz) {
 return LogManager.getLogger(clazz.getName());
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public Logger getLogger(Class<?> key) {
  return new Log4jLogger(LogManager.getLogger(key));
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public Logger getLogger(Class<?> key) {
  return new Log4jLogger(LogManager.getLogger(key));
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public Logger getLogger(String key) {
  return new Log4jLogger(LogManager.getLogger(key));
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public Logger getLogger(String key) {
  return new Log4jLogger(LogManager.getLogger(key));
}

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

/**
  * Disables Zk- and HBase client logging
  */
 static void disableZkAndClientLoggers() {
  // disable zookeeper log to avoid it mess up command output
  Logger zkLogger = LogManager.getLogger("org.apache.zookeeper");
  zkLogger.setLevel(Level.OFF);
  // disable hbase zookeeper tool log to avoid it mess up command output
  Logger hbaseZkLogger = LogManager.getLogger("org.apache.hadoop.hbase.zookeeper");
  hbaseZkLogger.setLevel(Level.OFF);
  // disable hbase client log to avoid it mess up command output
  Logger hbaseClientLogger = LogManager.getLogger("org.apache.hadoop.hbase.client");
  hbaseClientLogger.setLevel(Level.OFF);
 }
}

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

private static org.apache.log4j.Logger getLog4jLogger(String loggerName) {
 Logger logger = LoggerFactory.getLogger(loggerName);
 if (logger instanceof Log4JLogger) {
  Log4JLogger httpLog4JLog = (Log4JLogger)logger;
  return httpLog4JLog.getLogger();
 } else if (logger instanceof Log4jLoggerAdapter) {
  return LogManager.getLogger(loggerName);
 } else {
  return null;
 }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

public Logger getLogger(Class<?> key) {
  return new Log4jLogger(LogManager.getLogger(key));
}

代码示例来源:origin: org.slf4j/slf4j-log4j12

public Logger getLogger(String name) {
    Logger slf4jLogger = loggerMap.get(name);
    if (slf4jLogger != null) {
      return slf4jLogger;
    } else {
      org.apache.log4j.Logger log4jLogger;
      if (name.equalsIgnoreCase(Logger.ROOT_LOGGER_NAME))
        log4jLogger = LogManager.getRootLogger();
      else
        log4jLogger = LogManager.getLogger(name);

      Logger newInstance = new Log4jLoggerAdapter(log4jLogger);
      Logger oldInstance = loggerMap.putIfAbsent(name, newInstance);
      return oldInstance == null ? newInstance : oldInstance;
    }
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

public Logger getLogger(Class<?> key) {
  return new Log4jLogger(LogManager.getLogger(key));
}

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

@ManagedOperation(description="Activate info level")
@ManagedOperationParameters({@ManagedOperationParameter(name = "category", description = "the log4j category to set")})
public void activateInfo(String category) {
  LogManager.getLogger(category).setLevel(Level.INFO);
}

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

@ManagedOperation(description="Activate fatal level")
@ManagedOperationParameters({@ManagedOperationParameter(name = "category", description = "the log4j category to set")})
public void activateFatal(String category) {
  LogManager.getLogger(category).setLevel(Level.FATAL);
}

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

@ManagedOperation(description="Activate warn level")
@ManagedOperationParameters({@ManagedOperationParameter(name = "category", description = "the log4j category to set")})
public void activateWarn(String category) {
  LogManager.getLogger(category).setLevel(Level.WARN);
}

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

@Override
protected int doWork() throws IOException {
 if (!isVerbose) {
   LogManager.getLogger(ZooKeeper.class.getName()).setLevel(Level.WARN);
 }
 if (numTables > 1) {
  return parallelLoadTables();
 } else {
  return loadTable();
 }
}

代码示例来源:origin: apache/incubator-gobblin

@Test
public void testKafkaReporter() {
 TestAppender testAppender = new TestAppender();
 Logger logger = LogManager.getLogger(LoggingPusher.class.getName());
 logger.addAppender(testAppender);
 LoggingPusher<String> loggingPusher = new LoggingPusher<String>("broker", "topic", Optional.absent());
 loggingPusher.pushMessages(ImmutableList.of("message1", "message2"));
 Assert.assertEquals(testAppender.events.size(), 2);
 Assert.assertEquals(testAppender.events.get(0).getRenderedMessage(), "Pushing to broker:topic: message1");
 Assert.assertEquals(testAppender.events.get(1).getRenderedMessage(), "Pushing to broker:topic: message2");
 logger.removeAppender(testAppender);
}

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

@ManagedOperation(description="Retrieve the category log level")
@ManagedOperationParameters({@ManagedOperationParameter(name = "category", description = "the log4j category")})
public String getLevel(String category) {
  return LogManager.getLogger(category).getLevel().toString();
}

相关文章