]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.runtime/scl/LoggingMDC.scl
Added support for creating markers and changing MDC in SCL logging
[simantics/platform.git] / bundles / org.simantics.scl.runtime / scl / LoggingMDC.scl
diff --git a/bundles/org.simantics.scl.runtime/scl/LoggingMDC.scl b/bundles/org.simantics.scl.runtime/scl/LoggingMDC.scl
new file mode 100644 (file)
index 0000000..a8babda
--- /dev/null
@@ -0,0 +1,19 @@
+include "LoggingJava"
+
+importJava "org.slf4j.MDC" where
+    get    :: String -> <Proc> Maybe String
+    put    :: String -> String -> <Proc> ()
+    remove :: String -> <Proc> ()
+
+putOrRemove :: String -> Maybe String -> <Proc> ()
+putOrRemove key (Just value) = put key value
+putOrRemove key Nothing      = remove key
+
+@inline
+withContext :: String -> String -> (<e> a) -> <e,Proc> a
+withContext key value procedure = result
+  where
+    oldValue = get key
+    put key value
+    result = procedure
+    putOrRemove key oldValue
\ No newline at end of file