2016-07-21 27 views
0

これはLog4J2's siteからXML構成の例である:このLog4J2設定と同等のJSONは何ですか?

私はいくつかの異なるJSONのバリエーションを試してみましたが、それらのすべてがNullPointExceptionまたは類似した何かで失敗します。

は例えば、以下の構成が失敗します。

 "PatternLayout": { 
     "MarkerPatternSelector": { 
      "defaultPattern": [%-5level] %c{1.} %msg%n", 
      "PatternMatch": { 
      "key": "FLOW", 
      "pattern": "[%-5level] %c{1.} ====== %C{1.}.%M:%L %msg ======%n" 
      } 
     } 
     } 

このXML構成のための正しいJSONに相当何ですか?

答えて

1

問題は、使用していたLog4J2のバージョン(2.3)に起因しています。 2.6.2はこの機能をサポートしています。具体的には、ここでのファクトリメソッドは2.6.2にあります:

@PluginFactory 
public static PatternLayout createLayout(
     @PluginAttribute(value = "pattern", defaultString = DEFAULT_CONVERSION_PATTERN) final String pattern, 
     @PluginConfiguration final Configuration config, 
     @PluginElement("Replace") final RegexReplacement replace, 
     @PluginAttribute(value = "charset", defaultString = "UTF-8") final Charset charset, 
     @PluginAttribute(value = "alwaysWriteExceptions", defaultBoolean = true) final boolean alwaysWriteExceptions, 
     @PluginAttribute(value = "noConsoleNoAnsi", defaultBoolean = false) final boolean noConsoleNoAnsi, 
     @PluginAttribute("header") final String header, 
     @PluginAttribute("footer") final String footer) { 
    return newBuilder() 
     .withPattern(pattern) 
     .withConfiguration(config) 
     .withRegexReplacement(replace) 
     .withCharset(charset) 
     .withAlwaysWriteExceptions(alwaysWriteExceptions) 
     .withNoConsoleNoAnsi(noConsoleNoAnsi) 
     .withHeader(header) 
     .withFooter(footer) 
     .build(); 
} 

APIドキュメントサイトのURL(https://logging.apache.org/log4j/2.x)は下私を置く:

@PluginFactory 
public static PatternLayout createLayout(
     @PluginAttribute(value = "pattern", defaultString = DEFAULT_CONVERSION_PATTERN) final String pattern, 
     @PluginElement("PatternSelector") final PatternSelector patternSelector, 
     @PluginConfiguration final Configuration config, 
     @PluginElement("Replace") final RegexReplacement replace, 
     // LOG4J2-783 use platform default by default, so do not specify defaultString for charset 
     @PluginAttribute(value = "charset") final Charset charset, 
     @PluginAttribute(value = "alwaysWriteExceptions", defaultBoolean = true) final boolean alwaysWriteExceptions, 
     @PluginAttribute(value = "noConsoleNoAnsi", defaultBoolean = false) final boolean noConsoleNoAnsi, 
     @PluginAttribute("header") final String headerPattern, 
     @PluginAttribute("footer") final String footerPattern) { 
    return newBuilder() 
     .withPattern(pattern) 
     .withPatternSelector(patternSelector) 
     .withConfiguration(config) 
     .withRegexReplacement(replace) 
     .withCharset(charset) 
     .withAlwaysWriteExceptions(alwaysWriteExceptions) 
     .withNoConsoleNoAnsi(noConsoleNoAnsi) 
     .withHeader(headerPattern) 
     .withFooter(footerPattern) 
     .build(); 
} 

そして、ここではそれが2.3にように見えた方法ですすべての2.xのバージョンが互換性があるという印象。

関連する問題