本文整理汇总了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();
}