From eedebdfa83f012d13a76cb0658089462ad7bb90e Mon Sep 17 00:00:00 2001 From: Mattias Hellborg Arthursson Date: Fri, 14 Nov 2014 08:03:39 +0100 Subject: [PATCH] Added hook method for adding custom data to the produced JSON map. --- .../logback/contrib/json/classic/JsonLayout.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/json/classic/src/main/java/ch/qos/logback/contrib/json/classic/JsonLayout.java b/json/classic/src/main/java/ch/qos/logback/contrib/json/classic/JsonLayout.java index cc5885e..75d2c09 100755 --- a/json/classic/src/main/java/ch/qos/logback/contrib/json/classic/JsonLayout.java +++ b/json/classic/src/main/java/ch/qos/logback/contrib/json/classic/JsonLayout.java @@ -219,9 +219,23 @@ protected Map toJsonMap(ILoggingEvent event) { } } + addCustomDataToJsonMap(map, event); return map; } + /** + * Override to add custom data to the produced JSON from the logging event. + * Useful if you e.g. want to include the parameter array as a separate json attribute. + * + * @param map the map for JSON serialization, populated with data corresponding to the + * configured attributes. Add new entries from the event to this map to have + * them included in the produced JSON. + * @param event the logging event to extract data from. + */ + protected void addCustomDataToJsonMap(Map map, ILoggingEvent event) { + // Nothing to do in default implementation + } + public boolean isIncludeLevel() { return includeLevel; }