]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/reporting/SCLReporting.java
Expose CommandSession in SCL
[simantics/platform.git] / bundles / org.simantics.scl.runtime / src / org / simantics / scl / runtime / reporting / SCLReporting.java
index 8870eb98ea16fd90a41179094a8269fb23fc803f..5266b13a21e61c7892a6efc39698abf60a18c4a8 100644 (file)
@@ -6,6 +6,8 @@ import java.io.IOException;
 import org.simantics.scl.runtime.SCLContext;
 import org.simantics.scl.runtime.function.Function;
 import org.simantics.scl.runtime.tuple.Tuple0;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Static methods for calling the currently active {@link SCLReportingHandler}.
@@ -14,6 +16,13 @@ import org.simantics.scl.runtime.tuple.Tuple0;
  */
 public class SCLReporting {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(SCLReporting.class);
+
+    public static SCLReportingHandler getCurrentReportingHandler() {
+        SCLReportingHandler handler = ((SCLReportingHandler)SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER));
+        return handler == null ? SCLReportingHandler.DEFAULT : handler;
+    }
+    
     public static void print(String text) {
         SCLReportingHandler handler = ((SCLReportingHandler)SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER));
         if(handler != null)
@@ -27,7 +36,7 @@ public class SCLReporting {
         if(handler != null)
             handler.printError(text);
         else
-            System.err.println(text);
+            LOGGER.error(text);
     }
     
     public static void didWork(double amount) {
@@ -109,4 +118,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);
+        }
+    }
 }