當前位置: 首頁>>代碼示例>>Java>>正文


Java ILoggingEvent.getCallerData方法代碼示例

本文整理匯總了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);
            }
        });
    }
}
 
開發者ID:Sberned,項目名稱:kafka-logback,代碼行數:23,代碼來源:CustomJsonLayout.java

示例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();
}
 
開發者ID:hmcts,項目名稱:java-logging,代碼行數:33,代碼來源:ReformLoggingLayout.java


注:本文中的ch.qos.logback.classic.spi.ILoggingEvent.getCallerData方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。