本文整理汇总了Java中ch.qos.logback.classic.spi.LoggingEvent.setThrowableProxy方法的典型用法代码示例。如果您正苦于以下问题:Java LoggingEvent.setThrowableProxy方法的具体用法?Java LoggingEvent.setThrowableProxy怎么用?Java LoggingEvent.setThrowableProxy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ch.qos.logback.classic.spi.LoggingEvent
的用法示例。
在下文中一共展示了LoggingEvent.setThrowableProxy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeEvent
import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
private LoggingEvent makeEvent(Level level, String message, Throwable th) {
LoggingEvent event = new LoggingEvent();
event.setLoggerName(CloudWatchAppender.class.getName());
event.setLevel(level);
event.setMessage(message);
event.setTimeStamp(System.currentTimeMillis());
if (th != null) {
event.setThrowableProxy(new ThrowableProxy(th));
}
return event;
}
示例2: onLog
import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
@Override
public void onLog(LogEntry logEntry) {
final LoggingEvent loggingEvent = new LoggingEvent();
loggingEvent.setTimeStamp(logEntry.getTimestamp());
loggingEvent.setLoggerName(logEntry.getLoggerName());
loggingEvent.setLevel(Level.valueOf(logEntry.getLogLevel().name()));
loggingEvent.setThreadName(logEntry.getThreadName());
Object [] formatObjects = new Object[] {logEntry.getHost(),
getSimpleClassName(logEntry.getSourceClassName()),
logEntry.getSourceMethodName(),
logEntry.getFileName(),
logEntry.getLineNumber(),logEntry.getMessage()};
loggingEvent.setMessage(MESSAGE_FORMAT.get().format(formatObjects));
// Prints the throwable and stack trace.
LogThrowable logThrowable = logEntry.getThrowable();
if (logThrowable != null) {
loggingEvent.setThrowableProxy(new ThrowableProxy(setThrowable(logThrowable)));
}
if (logger instanceof Logger) {
((Logger) logger).callAppenders(loggingEvent);
} else {
logger.info("Logger is not instance of ch.qos.logback.classic.Logger. Logger event is: {}", loggingEvent);
}
}
示例3: layoutWithException
import ch.qos.logback.classic.spi.LoggingEvent; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void layoutWithException() throws Exception {
layout.setPattern("%level %thread %msg %ex");
LoggingEvent le = createLoggingEvent();
le.setThrowableProxy(new ThrowableProxy(new Exception("test Exception")));
String result = layout.doLayout(le);
String stringToParse = layout.getFileHeader();
stringToParse = stringToParse + layout.getPresentationHeader();
stringToParse += result;
stringToParse += "</table></body></html>";
// System.out.println(stringToParse);
Document doc = parseOutput(stringToParse);
Element rootElement = doc.getRootElement();
Element bodyElement = rootElement.element("body");
Element tableElement = bodyElement.element("table");
List<Element> trElementList = tableElement.elements();
Element exceptionRowElement = trElementList.get(2);
Element exceptionElement = exceptionRowElement.element("td");
assertEquals(3, tableElement.elements().size());
assertTrue(exceptionElement.getText().contains(
"java.lang.Exception: test Exception"));
}