From: Hannu Niemistö Date: Fri, 2 Nov 2018 14:13:48 +0000 (+0200) Subject: Added support for creating markers and changing MDC in SCL logging X-Git-Tag: v1.43.0~136^2~297 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=9845a372968046da2f1e99a37ca550ce8f38fb31 Added support for creating markers and changing MDC in SCL logging gitlab #178 Change-Id: Id2996c969d3812a6ff9c20fca88307d629be7354 --- diff --git a/bundles/org.simantics.scl.runtime/scl/Logging.scl b/bundles/org.simantics.scl.runtime/scl/Logging.scl index a781fa01f..67f48ecd2 100644 --- a/bundles/org.simantics.scl.runtime/scl/Logging.scl +++ b/bundles/org.simantics.scl.runtime/scl/Logging.scl @@ -1 +1,7 @@ include "LoggingJava" +include "LoggingMDC" as MDC + +importJava "org.slf4j.MarkerFactory" where + // Note: this method is pure by purpose, because MarkerFactory should always return the same marker + @JavaName getMarker + marker :: String -> Marker \ No newline at end of file diff --git a/bundles/org.simantics.scl.runtime/scl/LoggingMDC.scl b/bundles/org.simantics.scl.runtime/scl/LoggingMDC.scl new file mode 100644 index 000000000..a8babda35 --- /dev/null +++ b/bundles/org.simantics.scl.runtime/scl/LoggingMDC.scl @@ -0,0 +1,19 @@ +include "LoggingJava" + +importJava "org.slf4j.MDC" where + get :: String -> Maybe String + put :: String -> String -> () + remove :: String -> () + +putOrRemove :: String -> Maybe String -> () +putOrRemove key (Just value) = put key value +putOrRemove key Nothing = remove key + +@inline +withContext :: String -> String -> ( a) -> a +withContext key value procedure = result + where + oldValue = get key + put key value + result = procedure + putOrRemove key oldValue \ No newline at end of file