本文整理匯總了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"));
}