Logging in Scout Framework [message #581130] |
Wed, 19 May 2010 06:06  |
Eclipse User |
|
|
|
Until now we use for logging our own logging-facade which is very similar to Apache Commons or SLF4j.
We'd like to remove this dupplication of functionality and move to a widely used logging-facade.
Has the eclipse community a favorite? Is the use of one preferred?
Thanks for your insights.
Greetings
Stephan
|
|
|
|
|
Re: Logging in Scout Framework [message #667255 is a reply to message #581130] |
Wed, 27 April 2011 12:27  |
Eclipse User |
|
|
|
In Eclipse Scout, we have a transparent way for doing logging. The factory 'ScoutLogManager' is used to create a logging strategy. By default, JUL (java.util.logging) is used. But it is possible to change that behaviour by setting the config.ini property 'org.eclipse.scout.log' to 'eclipse' in order to make use of the Eclipse Log Framework. Furthermore, a custom log implementation can be registered by creating a fragment to the host-Plug-In 'org.eclipse.scout.commons'. In turn, if the config.ini property '[I]org.eclipse.scout.log[/I' is not set, the ScoutLogManager looks for a class named 'org.eclipse.scout.commons.logger.CustomLogManager' within its classpath. If found, this class is instantiated and used as logging strategy.
Also, it is possible to set dynamically a global log level to all loggers no matter of which log level they currently are logging. Of course, this can be made undone and all loggers have their origin log level again.
Furthermore, it is possible to record log messages for a certain amount of time. When recording is stopped, a file is created containing all log messages since recording was started.
The combination of the recording functionality together with the change of the log level at runtime facilitates debugging. This is especially true, if systems are to be maintained to easily get some valuable log output.
Snipped
The snipped below demonstrates you how to register keystrokes in Scout desktop to make use of this new functionality:
With the keystrokes 'CTRL-Shift-1' to 'CTRL-Shift-4', the log level can be changed at runtime. Also, recording of log messages is turned on if not the case yet.
To cancel recording and set the configuration to its origin state, 'CTRL-Shift-0' can be pressed.
public class Desktop extends AbstractDesktop {
/**
* Instruct {@link ScoutLogManager} to load its origin logging configuration and turn off recording of log messages.
* If recording was active, a file is displayed to the user containing all log messages since recording was started.
*/
@Order(10)
public class LogLevelDefaultKeyStroke extends AbstractKeyStroke {
@Override
protected String getConfiguredKeyStroke() {
return "ctrl-shift-0";
}
@Override
protected void execAction() throws ProcessingException {
ScoutLogManager.setGlobalLogLevel(null);
File file = ScoutLogManager.stopRecording();
if (file != null) {
Desktop.this.setStatusText("LOG level is set back to default and recording of log messages turned off");
SERVICES.getService(IShellService.class).shellOpen(file.getAbsolutePath());
}
else {
Desktop.this.setStatusText("LOG level is set back to normal");
}
}
}
/**
* Instruct {@link ScoutLogManager} to only log messages of the severity ERROR and worse.
* Also, turn on recording of log messages if not done yet.
*/
@Order(20)
public class LogLevelErrorKeyStroke extends AbstractKeyStroke {
@Override
protected String getConfiguredKeyStroke() {
return "ctrl-shift-1";
}
@Override
protected void execAction() throws ProcessingException {
ScoutLogManager.setGlobalLogLevel(IScoutLogger.LEVEL_ERROR);
if (ScoutLogManager.startRecording()) {
Desktop.this.setStatusText("LOG level is set to ERROR and recording of log messages turned on");
}
else {
Desktop.this.setStatusText("LOG level is set to ERROR");
}
}
}
/**
* Instruct {@link ScoutLogManager} to only log messages of the severity WARNING and worse.
* Also, turn on recording of log messages if not done yet.
*/
@Order(30)
public class LogLevelWarningKeyStroke extends AbstractKeyStroke {
@Override
protected String getConfiguredKeyStroke() {
return "ctrl-shift-2";
}
@Override
protected void execAction() throws ProcessingException {
ScoutLogManager.setGlobalLogLevel(IScoutLogger.LEVEL_WARN);
if (ScoutLogManager.startRecording()) {
Desktop.this.setStatusText("LOG level is set to WARNING and recording of log messages turned on");
}
else {
Desktop.this.setStatusText("LOG level is set to WARNING");
}
}
}
/**
* Instruct {@link ScoutLogManager} to only log messages of the severity INFO and worse.
* Also, turn on recording of log messages if not done yet.
*/
@Order(40)
public class LogLevelInfoKeyStroke extends AbstractKeyStroke {
@Override
protected String getConfiguredKeyStroke() {
return "ctrl-shift-3";
}
@Override
protected void execAction() throws ProcessingException {
ScoutLogManager.setGlobalLogLevel(IScoutLogger.LEVEL_INFO);
if (ScoutLogManager.startRecording()) {
Desktop.this.setStatusText("LOG level is set to INFO and recording of log messages turned on");
}
else {
Desktop.this.setStatusText("LOG level is set to INFO");
}
}
}
/**
* Instruct {@link ScoutLogManager} to only log messages of the severity DEBUG and worse.
* Also, turn on recording of log messages if not done yet.
*/
@Order(50)
public class DebugLogLevelKeyStroke extends AbstractKeyStroke {
@Override
protected String getConfiguredKeyStroke() {
return "ctrl-shift-4";
}
@Override
protected void execAction() throws ProcessingException {
ScoutLogManager.setGlobalLogLevel(IScoutLogger.LEVEL_DEBUG);
if (ScoutLogManager.startRecording()) {
Desktop.this.setStatusText("LOG level is set to DEBUG and recording of log messages turned on");
}
else {
Desktop.this.setStatusText("LOG level is set to DEBUG");
}
}
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.03608 seconds