-
Notifications
You must be signed in to change notification settings - Fork 127
Log_services
Modelio v4.0
Modelio API log services can be used to post messages in the Modelio log file.
Module log messages are messages which are only displayed when the Module is being either tested or debugged or under diagnostic. Therefore, do not use log message facilities when you need to display some information to the end-user as he would most probably not see it unless he visits the log file, an unlikely option. Instead, make the most of SWT GUI programming facilities to popup message or progress dialog where needed and keep log messages for diagnosing and debugging.
Log messages can be technical, somewhat verbose and numerous because they usually do not appear to the end-user in normal operating conditions. For the same reason, they generally do not need to be localized. However, be careful with performance, as too many log messages can actually slow down your Module operations. Log messages are posted with a severity level set to one of: Error, Warning, Info.
Modelio log is configurable (filtered by severity) and subject to end-user enabling/disabling. Log messages are not displayed in the standard conditions of use of Modelio. So if you get no log messages in the log, the first thing to check is that the log is currently active in Modelio.
Modelio being a RCP based it has no console window by default. However, for debugging purpose, a console can be displayed by adding the −consoleLog to the command line of Modelio. Note that the console window is displayed outside of Modelio, ie it is not a Modelio view!.
When the −consoleLog option is not present, the log messages are stored into a log file on the disk. This log file, named modelio.log , resides in the working directory of Modelio.
The Modelio API for logging messages is straightforward.
-
Get the Modelio log service
-
Call one of the provided logging methods
The log service is an instance of ILogService
, that can be obtained from the module context (IModulecontext
).
In the following code fragment, a module logs an information message about its current version at start time.
1public boolean start ()throws ModuleException 2{ 3 // get the name and the version of the module 4 String moduleName = this.module.getName(); 5 Version moduleVersion = this.module.getVersion(); 6 7 // get the Modelio log service 8 ILogService logService = this.module.getModuleContext().getLogService(); 9 10 // log an info message 11 String message = "Start of " + moduleName + " " + moduleVersion; 12 logService.info(message); 13 ... 14 return true; 15}
Three logging methods are available on ILogService
:
-
public void info(String message)
-
public void warning(String message)
-
public void error(String message)
You can use System.out.print
and System.err.print
in your code, but the messages won’t appear to the end-user unless you are using the -consoleLog flag on Modelio command line.
Let us repeat it here: when you need to inform the user of any ordinary condition of your module (end of task, command completion, processing results and so on) make the most of SWT GUI programming facilities to popup message or progress dialogs where needed and keep log messages for diagnosing and debugging.