当前位置: 首页>>代码示例>>Java>>正文


Java LogManager.getLogger方法代码示例

本文整理汇总了Java中org.apache.log4j.LogManager.getLogger方法的典型用法代码示例。如果您正苦于以下问题:Java LogManager.getLogger方法的具体用法?Java LogManager.getLogger怎么用?Java LogManager.getLogger使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.log4j.LogManager的用法示例。


在下文中一共展示了LogManager.getLogger方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSlowness

import org.apache.log4j.LogManager; //导入方法依赖的package包/类
@Test(expected = EventDeliveryException.class)
public void testSlowness() throws Throwable {
  ch = new SlowMemoryChannel(2000);
  Configurables.configure(ch, new Context());
  configureSource();
  props.put("log4j.appender.out2.Timeout", "1000");
  props.put("log4j.appender.out2.layout", "org.apache.log4j.PatternLayout");
  props.put("log4j.appender.out2.layout.ConversionPattern",
      "%-5p [%t]: %m%n");
  PropertyConfigurator.configure(props);
  Logger logger = LogManager.getLogger(TestLog4jAppender.class);
  Thread.currentThread().setName("Log4jAppenderTest");
  int level = 10000;
  String msg = "This is log message number" + String.valueOf(1);
  try {
    logger.log(Level.toLevel(level), msg);
  } catch (FlumeException ex) {
    throw ex.getCause();
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:21,代码来源:TestLog4jAppender.java

示例2: testLog4jAppender

import org.apache.log4j.LogManager; //导入方法依赖的package包/类
@Test
public void testLog4jAppender() throws IOException {
  configureSource();
  PropertyConfigurator.configure(props);
  Logger logger = LogManager.getLogger(TestLog4jAppender.class);
  for (int count = 0; count <= 1000; count++) {
    /*
     * Log4j internally defines levels as multiples of 10000. So if we
     * create levels directly using count, the level will be set as the
     * default.
     */
    int level = ((count % 5) + 1) * 10000;
    String msg = "This is log message number" + String.valueOf(count);

    logger.log(Level.toLevel(level), msg);
    Transaction transaction = ch.getTransaction();
    transaction.begin();
    Event event = ch.take();
    Assert.assertNotNull(event);
    Assert.assertEquals(new String(event.getBody(), "UTF8"), msg);

    Map<String, String> hdrs = event.getHeaders();

    Assert.assertNotNull(hdrs.get(Log4jAvroHeaders.TIMESTAMP.toString()));

    Assert.assertEquals(Level.toLevel(level),
        Level.toLevel(Integer.valueOf(hdrs.get(Log4jAvroHeaders.LOG_LEVEL
            .toString()))
        ));

    Assert.assertEquals(logger.getName(),
        hdrs.get(Log4jAvroHeaders.LOGGER_NAME.toString()));

    Assert.assertEquals("UTF8",
        hdrs.get(Log4jAvroHeaders.MESSAGE_ENCODING.toString()));
    transaction.commit();
    transaction.close();
  }

}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:41,代码来源:TestLog4jAppender.java

示例3: testLayout

import org.apache.log4j.LogManager; //导入方法依赖的package包/类
@Test
public void testLayout() throws IOException {
  configureSource();
  props.put("log4j.appender.out2.layout", "org.apache.log4j.PatternLayout");
  props.put("log4j.appender.out2.layout.ConversionPattern",
      "%-5p [%t]: %m%n");
  PropertyConfigurator.configure(props);
  Logger logger = LogManager.getLogger(TestLog4jAppender.class);
  Thread.currentThread().setName("Log4jAppenderTest");
  for (int count = 0; count <= 100; count++) {
    /*
     * Log4j internally defines levels as multiples of 10000. So if we
     * create levels directly using count, the level will be set as the
     * default.
     */
    int level = ((count % 5) + 1) * 10000;
    String msg = "This is log message number" + String.valueOf(count);

    logger.log(Level.toLevel(level), msg);
    Transaction transaction = ch.getTransaction();
    transaction.begin();
    Event event = ch.take();
    Assert.assertNotNull(event);
    StringBuilder builder = new StringBuilder();
    builder.append("[").append("Log4jAppenderTest").append("]: ")
        .append(msg);
    //INFO seems to insert an extra space, so lets split the string.
    String eventBody = new String(event.getBody(), "UTF-8");
    String eventLevel = eventBody.split("\\s+")[0];
    Assert.assertEquals(Level.toLevel(level).toString(), eventLevel);
    Assert.assertEquals(
        new String(event.getBody(), "UTF8").trim()
            .substring(eventLevel.length()).trim(), builder.toString());

    Map<String, String> hdrs = event.getHeaders();

    Assert.assertNotNull(hdrs.get(Log4jAvroHeaders.TIMESTAMP.toString()));

    Assert.assertEquals(Level.toLevel(level),
        Level.toLevel(Integer.parseInt(hdrs.get(Log4jAvroHeaders.LOG_LEVEL
            .toString()))));

    Assert.assertEquals(logger.getName(),
        hdrs.get(Log4jAvroHeaders.LOGGER_NAME.toString()));

    Assert.assertEquals("UTF8",
        hdrs.get(Log4jAvroHeaders.MESSAGE_ENCODING.toString()));
    transaction.commit();
    transaction.close();
  }


}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:54,代码来源:TestLog4jAppender.java

示例4: setLevel

import org.apache.log4j.LogManager; //导入方法依赖的package包/类
@Override
public void setLevel(String loggerName, String levelName) {
    checkNotNull(loggerName, "loggerName");
    checkNotNull(levelName, "levelName");
    LOGGER.debug("updating logger level (loggerName={}, levelName={})", loggerName, levelName);
    Logger logger = LogManager.getLogger(loggerName);
    Level level = Level.toLevel(levelName);
    logger.setLevel(level);
}
 
开发者ID:vy,项目名称:hrrs,代码行数:10,代码来源:Log4jLoggerLevelAccessor.java

示例5: log

import org.apache.log4j.LogManager; //导入方法依赖的package包/类
private void log(LogMessage logMessage, LogLevel level, String loggerName) {
	String logMessageString;
	if (config.getLogInPlainString()) {
		StringBuilder sb = new StringBuilder();
		sb.append("[CID: ").append(logMessage.getCorrelationId());
		if (StringUtils.isNotBlank(logMessage.getCorrelationIdLocal())) {
			sb.append(" CID.Local: ").append(logMessage.getCorrelationIdLocal());
		}
		sb.append("] ").append(logMessage.getMessage());
		String varsInString = LogHelper.variablesToString(logMessage.getVariables(), config.getLogVariableType());
		if (varsInString.length() > 0) {
			sb.append(" [").append(varsInString).append("]");
		}
		if (logMessage.getThrowable() != null) {
			Throwable t = logMessage.getThrowable();
			sb.append("\nException: ").append(ExceptionUtils.getMessage(t)).append(" ")
					.append(ExceptionUtils.getStackTrace(logMessage.getThrowable()));
			sb.append("");
		}
		logMessageString = sb.toString();
	} else {
		TimeZone tz = TimeZone.getTimeZone("UTC");
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
		df.setTimeZone(tz);
		logMessage.setTimestamp(df.format(new Date()));
		logMessage.setLevel(level.toString());
		logMessage.setLogger(loggerName);
		logMessage.setThread(Thread.currentThread().toString());
		Gson gson = new GsonBuilder().disableHtmlEscaping().disableHtmlEscaping().create();
		logMessageString = gson.toJson(logMessage);
	}

	Logger logger = LogManager.getLogger(loggerName);
	switch (level) {
	case INFO:
		logger.info(logMessageString);
		break;
	case ERROR:
		logger.error(logMessageString);
		break;
	case FATAL:
		logger.fatal(logMessageString);
		break;
	case DEBUG:
		logger.debug(logMessageString);
		break;
	}
}
 
开发者ID:iac-m,项目名称:mule-json-logger,代码行数:49,代码来源:JsonLogger.java

示例6: getLogger

import org.apache.log4j.LogManager; //导入方法依赖的package包/类
public Logger getLogger(Class<?> key) {
	return new Log4jLogger(LogManager.getLogger(key));
}
 
开发者ID:eXcellme,项目名称:eds,代码行数:4,代码来源:Log4jLoggerAdapter.java

示例7: toLog4j

import org.apache.log4j.LogManager; //导入方法依赖的package包/类
public static Logger toLog4j(org.slf4j.Logger logger) {
  return LogManager.getLogger(logger.getName());
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:4,代码来源:GenericTestUtils.java

示例8: testLog4jAppenderFailureUnsafeMode

import org.apache.log4j.LogManager; //导入方法依赖的package包/类
@Test
public void testLog4jAppenderFailureUnsafeMode() throws Throwable {
  configureSource();
  props.setProperty("log4j.appender.out2.UnsafeMode", String.valueOf(true));
  PropertyConfigurator.configure(props);
  Logger logger = LogManager.getLogger(TestLog4jAppender.class);
  source.stop();
  sendAndAssertFail(logger);

}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:11,代码来源:TestLog4jAppender.java

示例9: testLog4jAppenderFailureNotUnsafeMode

import org.apache.log4j.LogManager; //导入方法依赖的package包/类
@Test(expected = EventDeliveryException.class)
public void testLog4jAppenderFailureNotUnsafeMode() throws Throwable {
  configureSource();
  PropertyConfigurator.configure(props);
  Logger logger = LogManager.getLogger(TestLog4jAppender.class);
  source.stop();
  sendAndAssertFail(logger);

}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:10,代码来源:TestLog4jAppender.java

示例10: getLevel

import org.apache.log4j.LogManager; //导入方法依赖的package包/类
@Override
public String getLevel(String loggerName) {
    checkNotNull(loggerName, "loggerName");
    Logger logger = LogManager.getLogger(loggerName);
    return logger == null || logger.getLevel() == null ? null : logger.getLevel().toString();
}
 
开发者ID:vy,项目名称:hrrs,代码行数:7,代码来源:Log4jLoggerLevelAccessor.java


注:本文中的org.apache.log4j.LogManager.getLogger方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。