From: Hannu Niemistö Date: Thu, 8 Nov 2018 11:01:11 +0000 (+0200) Subject: Function printingToLogging redirecting print commands to logging X-Git-Tag: v1.43.0~136^2~289^2 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=8f1e3f237e21ecf19207ba1918041b0eefec4367;hp=d924aa9e2691606e0bc8044cce01aff4abcc7bc9 Function printingToLogging redirecting print commands to logging gitlab #178 Change-Id: I4ec4f47c463c3a641eb3de513f91d7212125b931 --- diff --git a/bundles/org.simantics.scl.runtime/scl/Logging.scl b/bundles/org.simantics.scl.runtime/scl/Logging.scl index 67f48ecd2..e8446dc3c 100644 --- a/bundles/org.simantics.scl.runtime/scl/Logging.scl +++ b/bundles/org.simantics.scl.runtime/scl/Logging.scl @@ -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 :: ( a) -> a \ No newline at end of file diff --git a/bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/reporting/SCLReporting.java b/bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/reporting/SCLReporting.java index bf3d6c68f..97ef75f8b 100644 --- a/bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/reporting/SCLReporting.java +++ b/bundles/org.simantics.scl.runtime/src/org/simantics/scl/runtime/reporting/SCLReporting.java @@ -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); + } + } }