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}.
*/
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)
if(handler != null)
handler.printError(text);
else
- System.err.println(text);
+ LOGGER.error(text);
}
public static void didWork(double amount) {
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);
+ }
+ }
}