From 8f1e3f237e21ecf19207ba1918041b0eefec4367 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Thu, 8 Nov 2018 13:01:11 +0200 Subject: [PATCH] Function printingToLogging redirecting print commands to logging gitlab #178 Change-Id: I4ec4f47c463c3a641eb3de513f91d7212125b931 --- bundles/org.simantics.scl.runtime/scl/Logging.scl | 6 +++++- .../scl/runtime/reporting/SCLReporting.java | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) 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); + } + } } -- 2.47.1