本文整理汇总了Java中org.apache.log4j.Logger.log方法的典型用法代码示例。如果您正苦于以下问题:Java Logger.log方法的具体用法?Java Logger.log怎么用?Java Logger.log使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.log4j.Logger
的用法示例。
在下文中一共展示了Logger.log方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSlowness
import org.apache.log4j.Logger; //导入方法依赖的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.Logger; //导入方法依赖的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: sendAndAssertFail
import org.apache.log4j.Logger; //导入方法依赖的package包/类
private void sendAndAssertFail(Logger logger) throws Throwable {
/*
* 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 = 20000;
try {
logger.log(Level.toLevel(level), "Test Msg");
} catch (FlumeException ex) {
ex.printStackTrace();
throw ex.getCause();
}
Transaction transaction = ch.getTransaction();
transaction.begin();
Event event = ch.take();
Assert.assertNull(event);
transaction.commit();
transaction.close();
}
示例4: testLayout
import org.apache.log4j.Logger; //导入方法依赖的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();
}
}
示例5: writeMessage
import org.apache.log4j.Logger; //导入方法依赖的package包/类
private void writeMessage(Logger logger, String message, Level level) {
Exception loggingException = null;
synchronized (auditLogManager) {
logger.log(level, message);
loggingException = auditLogManager.getException();
}
if (loggingException != null) {
LOGGER.error(Messages.AUDIT_LOGGING_FAILED, loggingException);
}
}
示例6: logOnce
import org.apache.log4j.Logger; //导入方法依赖的package包/类
/**
* Issue a message to the log but only if the same message has not
* been logged already in the same GATE session.
* This is intended for explanations or warnings that should not be
* repeated every time the same situation occurs.
*
* @param logger - the logger instance to use
* @param level - the severity level for the message
* @param message - the message itself
*/
public static void logOnce (Logger logger, Level level, String message) {
if(!alreadyLoggedMessages.contains(message)) {
logger.log(level, message);
alreadyLoggedMessages.add(message);
}
}