By default, MDWorkbench prints log messages to System.out
and System.err
.
You can change the logger using a subclass of com.sodius.mdw.core.util.log.Logger
and calling the setLogger()
API:
MDWorkbench mdw = MDWorkbenchFactory.create(); mdw.getConfiguration().setLogger(myLogger); ...
You may use predefined loggers, defined in the package com.sodius.mdw.core.util.log
This example logs messages into the file c:\log\myFile.log
:
File logFile = new File("c:\\log\\myFile.log"); mdw.getConfiguration().setLogger(new FileLogger(logFile));
This example redirects System.out
and System.err
streams to a file logger:
File logFile = new File("c:\\log\\myFile.log"); FileLogger logger = new FileLogger(logFile); mdw.getConfiguration().setLogger(logger); try { SystemStream.connect(logger); ... } finally { SystemStream.disconnect(); }
When executing a launch configuration, you can use a progress monitor
to report progresss and to have the ability to cancel the evaluation.
A progress monitor behavior is defined by the interface
com.sodius.mdw.core.util.progress.ProgressMonitor
.
Here is an example of progress monitor implementation that just reports progress messages to System.out
:
import com.sodius.mdw.core.util.progress.NullProgressMonitor; public class SystemStreamMonitor extends NullProgressMonitor { private String currentProgress = null; public void beginTask(String name, int totalWork) { progress(name); } public void subTask(String name) { progress(name); } public void setTaskName(String name) { progress(name); } private void progress(String name) { if (name != null && name.length() != 0) { if (! name.equals(this.currentProgress)) { this.currentProgress = name; System.out.println("[progress] " + this.currentProgress); } } } }
Now we can use this progress monitor as an argument of the evaluate()
method:
MDWorkbench mdw = MDWorkbenchFactory.create(); LaunchConfiguration configuration = ... mdw.evaluate(configuration, new SystemStreamMonitor());
During a launch execution, MDWorkbench regulary checks for end-user cancellation.
This is done by calling the method isCanceled()
of the progress monitor.
You may define your own progress monitor implementation that reports progress as a progress bar dialog,
with a cancel button that changes the state of the isCanceled()
method.