]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Added support for creating markers and changing MDC in SCL logging 17/2417/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Fri, 2 Nov 2018 14:13:48 +0000 (16:13 +0200)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Mon, 5 Nov 2018 11:53:32 +0000 (13:53 +0200)
gitlab #178

Change-Id: Id2996c969d3812a6ff9c20fca88307d629be7354

bundles/org.simantics.scl.runtime/scl/Logging.scl
bundles/org.simantics.scl.runtime/scl/LoggingMDC.scl [new file with mode: 0644]

index a781fa01fc52042705b07d2a2050cebc0b0999c6..67f48ecd2538c4e92fabce9ad94c9cd84b5c87f5 100644 (file)
@@ -1 +1,7 @@
 include "LoggingJava"
 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 (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