use of org.apache.log4j.spi.LoggingEvent in project gerrit by GerritCodeReview.
the class HttpLog method log.
@Override
public void log(final Request req, final Response rsp) {
final LoggingEvent event = new //
LoggingEvent(// fqnOfCategoryClass
Logger.class.getName(), // logger
log, // when
TimeUtil.nowMs(), // level
Level.INFO, // message text
"", // thread name
"HTTPD", // exception information
null, // current NDC string
null, // caller location
null, // MDC properties
null);
String uri = req.getRequestURI();
String qs = req.getQueryString();
if (qs != null) {
uri = uri + "?" + qs;
}
String user = (String) req.getAttribute(GetUserFilter.REQ_ATTR_KEY);
if (user != null) {
event.setProperty(P_USER, user);
}
set(event, P_HOST, req.getRemoteAddr());
set(event, P_METHOD, req.getMethod());
set(event, P_RESOURCE, uri);
set(event, P_PROTOCOL, req.getProtocol());
set(event, P_STATUS, rsp.getStatus());
set(event, P_CONTENT_LENGTH, rsp.getContentCount());
set(event, P_REFERER, req.getHeader("Referer"));
set(event, P_USER_AGENT, req.getHeader("User-Agent"));
async.append(event);
}
use of org.apache.log4j.spi.LoggingEvent in project symmetric-ds by JumpMind.
the class SymRollingFileAppenderTest method testMixedMessages.
@Test
public void testMixedMessages() throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
SymRollingFileAppender appender = getAppenderForTest(os);
Exception ex = new Exception("Test exception.");
Exception ex2 = new Exception("Test exception.");
LoggingEvent event1 = getLoggingEventForTest("Test Exception.", ex);
LoggingEvent event2 = getLoggingEventForTest("Test Exception.", ex2);
LoggingEvent event3 = getLoggingEventForTest("Test Exception.", ex);
LoggingEvent event4 = getLoggingEventForTest("Test Exception.", ex2);
appender.append(event1);
appender.append(event2);
appender.append(event3);
appender.append(event4);
String logging = os.toString("UTF8");
// 2016-08-11 11:55:38,487 ERROR [] [SymRollingFileAppenderTest] [main] Test Exception. StackTraceKey.init [Exception:1478675418]
Pattern initPattern = Pattern.compile(".*StackTraceKey.init \\[Exception:([0-9]*)\\].*", Pattern.DOTALL);
Matcher m = initPattern.matcher(logging);
if (m.matches()) {
{
String stackTraceKey = "Exception:" + m.group(1);
assertEquals(2, StringUtils.countMatches(logging, stackTraceKey));
}
m.matches();
{
String stackTraceKey = "Exception:" + m.group(1);
assertEquals(2, StringUtils.countMatches(logging, stackTraceKey));
}
} else {
fail("Didn't find proper logging pattern.");
}
}
use of org.apache.log4j.spi.LoggingEvent in project symmetric-ds by JumpMind.
the class SymRollingFileAppenderTest method testDistinctLogMessages.
@Test
public void testDistinctLogMessages() throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
SymRollingFileAppender appender = getAppenderForTest(os);
Exception ex = new Exception("Test exception.");
Exception ex2 = new Exception("Test exception.");
LoggingEvent event1 = getLoggingEventForTest("Test Exception.", ex);
LoggingEvent event2 = getLoggingEventForTest("Test Exception.", ex2);
appender.append(event1);
appender.append(event2);
String logging = os.toString("UTF8");
// 2016-08-11 11:55:38,487 ERROR [] [SymRollingFileAppenderTest] [main] Test Exception. StackTraceKey.init [Exception:1478675418]
Pattern initPattern = Pattern.compile(".*StackTraceKey.init \\[Exception:([0-9]*)\\].*", Pattern.DOTALL);
Matcher m = initPattern.matcher(logging);
if (m.matches()) {
{
String stackTraceKey = "Exception:" + m.group(1);
assertEquals(1, StringUtils.countMatches(logging, stackTraceKey));
}
m.matches();
{
String stackTraceKey = "Exception:" + m.group(1);
assertEquals(1, StringUtils.countMatches(logging, stackTraceKey));
}
} else {
fail("Didn't find proper logging pattern.");
}
}
use of org.apache.log4j.spi.LoggingEvent in project symmetric-ds by JumpMind.
the class SymRollingFileAppender method supressStackTrace.
protected LoggingEvent supressStackTrace(LoggingEvent event, String key) {
String message = getMessageWithKey(event, key);
LoggingEvent eventClone = new LoggingEvent(event.getFQNOfLoggerClass(), event.getLogger(), event.getTimeStamp(), event.getLevel(), message, event.getThreadName(), null, event.getNDC(), event.getLocationInformation(), event.getProperties());
return eventClone;
}
use of org.apache.log4j.spi.LoggingEvent in project symmetric-ds by JumpMind.
the class SymRollingFileAppenderTest method testDebugMode.
@Test
public void testDebugMode() throws Exception {
ByteArrayOutputStream os = new ByteArrayOutputStream(1024);
SymRollingFileAppender appender = getAppenderForTest(os);
Exception ex = new Exception("Test exception.");
LoggingEvent event1 = getLoggingEventForTest("Test Exception.", ex, Level.DEBUG);
LoggingEvent event2 = getLoggingEventForTest("Test Exception.", ex, Level.DEBUG);
LoggingEvent event3 = getLoggingEventForTest("Test Exception.", ex, Level.DEBUG);
appender.append(event1);
appender.append(event2);
appender.append(event3);
String logging = os.toString("UTF8");
// 2016-08-11 11:55:38,487 ERROR [] [SymRollingFileAppenderTest] [main] Test Exception. StackTraceKey.init [Exception:1478675418]
Pattern initPattern = Pattern.compile(".*StackTraceKey.init \\[Exception:([0-9]*)\\].*", Pattern.DOTALL);
Matcher m = initPattern.matcher(logging);
// everything should get logged with a DEBUG logger, so we should't find the StackTraceKey pattern.
assertFalse(m.matches());
}
Aggregations