當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。