Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "E4/Doc/Logging"

< E4‎ | Doc
(Related API's)
(Eclipse 3.x)
Line 46: Line 46:
 
</source>
 
</source>
  
Or, anything subclassing org.eclipse.core.runtime.Plugin can retrieve an implementation of ILog by calling getlog():
+
Or, anything subclassing org.eclipse.core.runtime.Plugin can retrieve an implementation of ILog by calling getLog():
 
<source lang="java">
 
<source lang="java">
 
public class MyPlugin extends Plugin {
 
public class MyPlugin extends Plugin {

Revision as of 14:49, 12 February 2010

Under Construction: Please read first!

The evolution of this document is a collaborative effort between a team of students at the University of Manitoba and the wider Eclipse community. Details about the project can be found here and on our Blog.

Your input is not just welcome; it is needed! Please contribute as your expertise allows, while adhering to our template. To send your feedback and any questions or comments you may have please email us. Also, while we do our very best to be as accurate and precise as possible, it is worth noting that we are students with limited exposure to the Eclipse platform, so if you see any incorrect technical details please let us know.

Description

The ability to output knowledge from an executing program is incredibly useful in determining a variety of problems including crashes, bugs and performance issues. The action of outputting this information during runtime to a storage medium (txt file, database, xml etc.) is known as logging and tracing and is common among all practices of software development. When implementing or using logging and tracing it is useful to be aware of the Singleton Pattern as it is the most common implementation of a logger.

Logging and tracing are the same concept but used to describe varying levels of information. Logging generally refers to higher level information, generally useful to System Administrators on a production system, whereas Tracing is generally more low-level and more useful to developers doing debugging of large systems.

Consumer

The consumption of the logging service is very straightforward; ask for a logger and then write to it.

Usage

Acquiring the logger can be done in several ways:

  1. Query the context:
    1. Ask for the OSGi LogService
    2. Ask for the Logger object
  2. Dependency Injection

The same LogService used in Eclipse 3.x can be queried for from the context and a separate logging service can be supplemented into each context. The Logger object can be queried in the same manner or be injected at runtime (see code samples).

Code Samples

Java

Querying for the LogService or Logger:

private LogService getLogService() {
  return (LogService) fEclipseContext.get(LogService.class.getName());
}
Logger log = (Logger) context.get(Logger.class.getName());

Dependency Injection:

@Inject private Logger logger;

Eclipse 3.x

The OSGi LogService can be retrieved via a ServiceTracker.

private LogService getLogService() {
  fLogServiceTracker = new ServiceTracker(fBundleContext, LogService.class.getName(), null);
  return (LogService) fLogServiceTracker.getService();
}

Or, anything subclassing org.eclipse.core.runtime.Plugin can retrieve an implementation of ILog by calling getLog():

public class MyPlugin extends Plugin {
  public void start(BundleContext context) throws Exception {
    getLog().log(new Status(IStatus.OK, "org.eclipse.e4.core", "Starting org.eclipse.e4.core bundle...");
  }
 
  public void stop(BundleContext context) throws Exception {
    getLog().log(new Status(IStatus.OK, "org.eclipse.e4.core", "Stopping org.eclipse.e4.core bundle...");
  }
}

Producer

At the time of writing, the default implementation of Logger is the WorkbenchLogger which dumps all log messages or debug messages to standard output.

Implementation

Implementing your own logger is straightforward, viewing the WorkbenchLogger source will provide sufficient info. The Logger can then be injected into the context in the standard fashion.

Related Materials

Related Services

Status Handling

Related API's

(need to link these to the api once it exists somewhere permanently)
org.eclipse.e4.core.services.Logger
org.eclipse.e4.workbench.ui.internal.WorkbenchLogger

See Also

Back to the top