Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » Logging in Scout Framework
Logging in Scout Framework [message #581130] Wed, 19 May 2010 10:06 Go to next message
Stephan Leicht Vogt is currently offline Stephan Leicht VogtFriend
Messages: 102
Registered: February 2010
Location: Baden Switzerland
Senior Member

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 #581153 is a reply to message #581130] Wed, 19 May 2010 11:31 Go to previous messageGo to next message
Arthur vD is currently offline Arthur vDFriend
Messages: 51
Registered: March 2010
Member
I assume the question is only about what the Scout using developer get to use when writing Scout code. How does it look like in the backend where the log entries from various third party libraries come together? I not so fondly remember an OSGi project where I've ended up with a dozen logging libraries (a few with org.osgi.service.log.LogService/LogListener implementations, most without) which all had to be consolidated.

Kind regards

Arthur
Re: Logging in Scout Framework [message #581171 is a reply to message #581153] Wed, 19 May 2010 11:42 Go to previous messageGo to next message
Stephan Leicht Vogt is currently offline Stephan Leicht VogtFriend
Messages: 102
Registered: February 2010
Location: Baden Switzerland
Senior Member

Well, yes and no. We would like to implement/use a logging facade that also simplifies your problem with dozens of logging libraries.
AFAIK SLF4j gives you the possibility to easily create wrappers over all logging implementations so every project will log over SLF4j and then into the logging framework of your choice (log4j/logback/jdk-logger...). Described in detail here: http://www.slf4j.org/legacy.html

Arthur, would that solve your past problems?

Greetings
Stephan
Re: Logging in Scout Framework [message #667255 is a reply to message #581130] Wed, 27 April 2011 16:27 Go to previous message
Daniel Wiehl is currently offline Daniel WiehlFriend
Messages: 25
Registered: April 2010
Junior Member
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");
      }
    }
  }
}
Previous Topic:Proposal Feedback
Next Topic:Recommendation Models for Scout?
Goto Forum:
  


Current Time: Fri Dec 19 11:56:40 GMT 2014

Powered by FUDForum. Page generated in 0.01716 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software