本文整理匯總了Java中ch.qos.logback.classic.spi.ILoggingEvent.getCallerData方法的典型用法代碼示例。如果您正苦於以下問題:Java ILoggingEvent.getCallerData方法的具體用法?Java ILoggingEvent.getCallerData怎麽用?Java ILoggingEvent.getCallerData使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ch.qos.logback.classic.spi.ILoggingEvent
的用法示例。
在下文中一共展示了ILoggingEvent.getCallerData方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addCustomDataToJsonMap
import ch.qos.logback.classic.spi.ILoggingEvent; //導入方法依賴的package包/類
@Override
protected void addCustomDataToJsonMap(Map<String, Object> map, ILoggingEvent event) {
add(HOST, includeHost, HOST_NAME, map);
if (event.hasCallerData()) {
StackTraceElement callerData = event.getCallerData()[0];
addLine(LINE_NUMBER, includeLineNumber, callerData.getLineNumber(), map);
add(CLASS_NAME, includeClassName, callerData.getClassName(), map);
add(METHOD_NAME, includeMethodName, callerData.getMethodName(), map);
add(FILE_NAME, includeFileName, callerData.getFileName(), map);
}
if (additionalFields != null) {
additionalFields.forEach(field -> {
String[] p = field.split("\\|");
if (p.length == 2) {
add(p[0], true, p[1], map);
} else {
addWarn("Unable to parse property string: " + field);
}
});
}
}
示例2: doLayout
import ch.qos.logback.classic.spi.ILoggingEvent; //導入方法依賴的package包/類
@Override
public String doLayout(ILoggingEvent event) {
Instant instant = Instant.ofEpochMilli(event.getTimeStamp());
ZonedDateTime dateTime = ZonedDateTime.ofInstant(instant, ZoneId.systemDefault());
StringBuilder log = new StringBuilder(dateTime.format(dateFormat));
log.append(String.format(" %-5s", event.getLevel().levelStr));
if (requireThread) {
log.append(String.format(" [%s]", event.getThreadName()));
}
int lineNumber = event.getCallerData().length > 0 ? event.getCallerData()[0].getLineNumber() : 0;
log.append(String.format(" %s:%d: ", event.getLoggerName(), lineNumber));
ThrowableProxy proxy = (ThrowableProxy) event.getThrowableProxy();
if (requireAlertLevel || requireErrorCode) {
appendExtraExceptionFlags(log, AbstractLoggingException.getFromThrowableProxy(proxy));
}
log.append(event.getFormattedMessage()).append(CoreConstants.LINE_SEPARATOR);
appendStackTrace(log, proxy);
if (proxy != null) {
loopCauses(log, proxy, 0);
}
return log.toString();
}