use of java.util.logging.LogRecord in project reversehttp by tonyg.
the class HttpServer method complain.
protected void complain(String msg, Throwable thrown) {
LogRecord r = new LogRecord(Level.SEVERE, msg);
r.setThrown(thrown);
Logger.getLogger(this.getClass().getName()).log(r);
}
use of java.util.logging.LogRecord in project reversehttp by tonyg.
the class ServiceContainer method handleRequest.
public void handleRequest(HttpRequest req) {
String targetLocalname = req.getRawPath().substring(1);
Address target = new Address(targetLocalname, domain);
String senderStr = req.getHeader("X-SMQP-Sender");
Address sender = senderStr == null ? null : Address.parse(senderStr);
String contentType = req.getHeader("Content-type");
String method = req.getHeader("X-SMQP-Method", "send");
Message msg = new Message(sender, target, req.getBody(), contentType, method);
try {
if (pathMap.containsKey(targetLocalname)) {
MessageHandler handler = pathMap.get(targetLocalname);
int responseCode = handler.handleMessage(msg);
req.setResponse(responseCode, "");
} else {
req.setResponse(404, "Destination not found");
}
} catch (Exception e) {
LogRecord r = new LogRecord(Level.SEVERE, "Exception at " + target);
r.setThrown(e);
Logger.getLogger(this.getClass().getName()).log(r);
req.setResponse(500, "Internal error");
}
}
use of java.util.logging.LogRecord in project commons by twitter.
the class JULBridgeHandlerTest method checkMessageWithResourceBundleIsFormatted.
@Test
public void checkMessageWithResourceBundleIsFormatted() {
ResourceBundle bundle = new ListResourceBundle() {
@Override
protected Object[][] getContents() {
return new Object[][] { { "test is successful", "le test fonctionne" } };
}
};
LogRecord record = new LogRecord(Level.FINEST, "test is successful");
record.setResourceBundle(bundle);
assertThat(JULBridgeHandler.formatMessage(record), is("le test fonctionne"));
}
use of java.util.logging.LogRecord in project commons by twitter.
the class JULBridgeHandlerTest method checkGetLoggerReturnsLoggerWithSameName.
@Test
public void checkGetLoggerReturnsLoggerWithSameName() {
LogRecord record = new LogRecord(Level.FINEST, "test message");
record.setLoggerName("test.checkGetLogger");
assertThat(new JULBridgeHandler().getLogger(record).getName(), is("test.checkGetLogger"));
}
use of java.util.logging.LogRecord in project commons by twitter.
the class JULBridgeHandlerTest method checkToLoggingEvent.
@Test
public void checkToLoggingEvent() {
LogRecord record = new LogRecord(Level.FINEST, "test is {0}");
record.setParameters(new Object[] { "successful" });
record.setThreadID(42);
Throwable t = new Throwable();
record.setThrown(t);
// source class and method names are usually inferred, but because there's no JUL in the stack
// frame, it won't work as expected.
record.setSourceClassName(getClass().getName());
record.setSourceMethodName("checkToLoggingEvent");
Logger log4jLogger = new JULBridgeHandler().getLogger(record);
org.apache.log4j.Level log4jLevel = JULBridgeLevelConverter.toLog4jLevel(Level.FINEST);
LoggingEvent event = JULBridgeHandler.toLoggingEvent(record, log4jLogger, log4jLevel, false);
assertThat(event.getLogger(), is((Category) log4jLogger));
assertThat(event.getLevel(), is(log4jLevel));
assertThat(event.getMessage(), is((Object) "test is successful"));
assertThat(event.getThreadName(), is("42"));
assertThat(event.getTimeStamp(), is(record.getMillis()));
assertThat(event.getThrowableInformation().getThrowable(), is(sameInstance(t)));
LocationInfo info = event.getLocationInformation();
assertThat(info.getClassName(), is(getClass().getName()));
assertThat(info.getMethodName(), is("checkToLoggingEvent"));
}
Aggregations