From 9845a372968046da2f1e99a37ca550ce8f38fb31 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Fri, 2 Nov 2018 16:13:48 +0200 Subject: [PATCH] Added support for creating markers and changing MDC in SCL logging gitlab #178 Change-Id: Id2996c969d3812a6ff9c20fca88307d629be7354 --- .../org.simantics.scl.runtime/scl/Logging.scl | 6 ++++++ .../scl/LoggingMDC.scl | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 bundles/org.simantics.scl.runtime/scl/LoggingMDC.scl 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 -- 2.47.1