]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Function printingToLogging redirecting print commands to logging 36/2436/1
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Thu, 8 Nov 2018 11:01:11 +0000 (13:01 +0200)
committerHannu Niemistö <hannu.niemisto@semantum.fi>
Thu, 8 Nov 2018 11:01:38 +0000 (13:01 +0200)
gitlab #178

Change-Id: I4ec4f47c463c3a641eb3de513f91d7212125b931

bundles/org.simantics.scl.runtime/scl/Logging.scl
bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/reporting/SCLReporting.java

index 67f48ecd2538c4e92fabce9ad94c9cd84b5c87f5..e8446dc3c28e80c7d6782f2c208c896776778f7a 100644 (file)
@@ -4,4 +4,8 @@ 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
+    marker :: String -> Marker
+
+importJava "org.simantics.scl.runtime.reporting.SCLReporting" where
+    "Redirects print commands to INFO level logging and printErrors to ERROR level logging."
+    printingToLogging :: (<e> a) -> <e> a
\ No newline at end of file
index bf3d6c68fb468d40f9dcd748cac00eb79f277648..97ef75f8b498e0d6a7382c7f84e626d0ceac8ee9 100644 (file)
@@ -113,4 +113,19 @@ public class SCLReporting {
             context.put(SCLReportingHandler.REPORTING_HANDLER, handler);
         }
     }
+    
+    public static Object printingToLogging(Function proc) {
+        SCLContext context = SCLContext.getCurrent();
+        SCLReportingHandler handler = (SCLReportingHandler)context.get(SCLReportingHandler.REPORTING_HANDLER);
+        if(handler == null)
+            handler = SCLReportingHandler.DEFAULT;
+        
+        context.put(SCLReportingHandler.REPORTING_HANDLER, SCLReportingHandler.DEFAULT);
+        
+        try {
+            return proc.apply(Tuple0.INSTANCE);
+        } finally {
+            context.put(SCLReportingHandler.REPORTING_HANDLER, handler);
+        }
+    }
 }