本文整理汇总了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();
}
}
示例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();
}
}
示例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();
}
}
示例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);
}
示例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;
}
}
示例6: getLogger
import org.apache.log4j.LogManager; //导入方法依赖的package包/类
public Logger getLogger(Class<?> key) {
return new Log4jLogger(LogManager.getLogger(key));
}
示例7: toLog4j
import org.apache.log4j.LogManager; //导入方法依赖的package包/类
public static Logger toLog4j(org.slf4j.Logger logger) {
return LogManager.getLogger(logger.getName());
}
示例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);
}
示例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);
}
示例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();
}