Merge "Function printingToLogging redirecting print commands to logging"
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 8 Nov 2018 12:25:21 +0000 (12:25 +0000)
committerGerrit Code Review <gerrit2@simantics>
Thu, 8 Nov 2018 12:25:21 +0000 (12:25 +0000)
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);
+        }
+    }
 }