3
有沒有人知道Dropwizard 0.7.1日誌的默認格式模式,如果沒有配置logFormat?Dropwizard默認的回滾模式
我需要某事像:
%d{HH:mm:ss.SSS} %-5level [%X{id}] [%X{format}] [%thread]: %class{0}::%method:%line - %msg%n
有沒有人知道Dropwizard 0.7.1日誌的默認格式模式,如果沒有配置logFormat?Dropwizard默認的回滾模式
我需要某事像:
%d{HH:mm:ss.SSS} %-5level [%X{id}] [%X{format}] [%thread]: %class{0}::%method:%line - %msg%n
的logback使用Layout interface的doLayout()
方法的實現翻譯事件記錄到字符串可以輸出,如the documentation概述。 Dropwizard provides an extension到PatternLayout
class(其反過來abstract PatternLayoutBase
class的擴展):
PatternLayout
需要記錄事件並返回一個String
。不過, 這個String
可以通過調整PatternLayout的轉換 模式來定製。
public class DropwizardLayout extends PatternLayout {
public DropwizardLayout(LoggerContext context, TimeZone timeZone) {
super();
setOutputPatternAsHeader(false);
getDefaultConverterMap().put("ex", PrefixedThrowableProxyConverter.class.getName());
getDefaultConverterMap().put("xEx", PrefixedExtendedThrowableProxyConverter.class.getName());
getDefaultConverterMap().put("rEx", PrefixedRootCauseFirstThrowableProxyConverter.class.getName());
setPattern("%-5p [%d{ISO8601," + timeZone.getID() + "}] %c: %m%n%rEx");
setContext(context);
}
}
這樣做是:
outputPatternAsHeader
被禁用,這是輸出要在任何日誌的頂部的字符串模式的標誌。確認所用模式的一種方法是在appender上啓用此標誌,如the logback documentation中所述。"%-5p [%d{ISO8601," + timeZone.getID() + "}] %c: %m%n%rEx"
。如果不顯式添加時區信息,則logback將使用JVM的時區或GMT。如果這是可以接受的,您可以使用%d
,因爲ISO8601
格式是默認格式。
根據源代碼'io.dropwizard.logging.DropwizardLayout',這是 '%-5p [%d {ISO8601, 「+ timeZone.getID()+」}]%C:%M% N%rEx'。由於我不確定timeZone和setPattern之前的其他行是否相關,因此將其留作評論。 – Natan 2014-11-25 11:10:34
@ user3280180 - 如果解決了,請標記答案。 – nullpointer 2016-12-12 16:51:45