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 "Papyrus/Papyrus Developer Guide/Papyrus Log"

(Pattern Info)
(5 intermediate revisions by 3 users not shown)
Line 2: Line 2:
  
 
== Activating Log ==  
 
== Activating Log ==  
 +
First, your plugin should depend on the '''org.eclipse.papyrus.infra.core.log.LogHelper''' plugin.
  
To benefit from the Papyrus log mechanism, you must add onto your bundle :  
+
Then, to benefit from the Papyrus log mechanism, you must add onto your bundle :  
  
 
A public static variable on your bundle activator :  
 
A public static variable on your bundle activator :  
  
         public class Activator extends AbstractUIPlugin {
+
        '''import org.eclipse.papyrus.infra.core.log.LogHelper;'''
         
+
       
 +
         public class Activator extends Plugin { // or AbstractUIPlugin
 +
         
 +
          '''/** Logging helper */'''
 
           ''' public static LogHelper log;'''
 
           ''' public static LogHelper log;'''
 
            
 
            
 +
          /**
 +
            * {@inheritDoc}
 +
            */
 
           public void start(BundleContext context) throws Exception {
 
           public void start(BundleContext context) throws Exception {
 
                 super.start(context);
 
                 super.start(context);
 
                 plugin = this;
 
                 plugin = this;
 +
                '''// register the login helper'''
 
                 '''log = new LogHelper(plugin);'''
 
                 '''log = new LogHelper(plugin);'''
 
           }
 
           }
         
 
 
         ...
 
         ...
 
         }
 
         }
Line 22: Line 29:
 
A static import of this variable on your class :  
 
A static import of this variable on your class :  
  
         '''import static org.eclipse.papyrus.*.Activator.log;'''
+
         '''import static org.eclipse.papyrus.[yourPluginName].Activator.log;'''
 
          
 
          
 
         public class CreateDiagramAction extends Action {
 
         public class CreateDiagramAction extends Action {
Line 77: Line 84:
 
==== Pattern Error ====
 
==== Pattern Error ====
  
  ${imp:importStatic(org.eclipse.papyrus.navigator.internal.Activator.log)}
+
    ${activatorLog}log.error("${cursor}");
  log.error("${cursor}");
+
  
 
== Displaying Log ==
 
== Displaying Log ==
Line 87: Line 93:
  
 
For more information, read this page : http://www.eclipse.org/eclipse/platform-core/documents/3.1/debug.html
 
For more information, read this page : http://www.eclipse.org/eclipse/platform-core/documents/3.1/debug.html
 +
 +
[[Category:Papyrus]]

Revision as of 11:54, 16 May 2014

Papyrus Log is using the log from Eclipse (see [1]). Logs are displayed in the "Error Log" view.

Activating Log

First, your plugin should depend on the org.eclipse.papyrus.infra.core.log.LogHelper plugin.

Then, to benefit from the Papyrus log mechanism, you must add onto your bundle :

A public static variable on your bundle activator :

       import org.eclipse.papyrus.infra.core.log.LogHelper;
       
       public class Activator extends Plugin { // or AbstractUIPlugin 
         
         /** Logging helper */
          public static LogHelper log;
          
          /**
           * {@inheritDoc}
           */
          public void start(BundleContext context) throws Exception {
               super.start(context);
               plugin = this;
               // register the login helper
               log = new LogHelper(plugin);
          }
       ...
       }

A static import of this variable on your class :

       import static org.eclipse.papyrus.[yourPluginName].Activator.log;
       
       public class CreateDiagramAction extends Action {
       
         public void run() {
              log.info("log");
         }
       }

Writing Log

There are three levels of log in Papyrus : info, debug, error

info

  log.info("..."); //$NON-NLS-1$

debug

A debug log is used for development and/or debug purposes only. It MUST be encapsulated with the condition log.isDebugEnabled().

  if (log.isDebugEnabled()) {
      log.debug("Start - CreateDiagramAction#run"); //$NON-NLS-1$
  }

error

 try {
   ...
 } catch (IOException io) {
      log.error(io);
      ...
 }

Help writing log

You can write a template for each of those logs to ease your development (Key assist / "Ctrl Space").

First, you have to install on your platform, the bundle "org.eclipse.papyrus.java.template" available on the developer Papyrus repository ([2])

Then, open the menu "Preferences" > "Java" > "Editor" > "Template"

Finally, create your template. The "name" corresponds to the shortcut you will use in your editor. The "context" is "Java".

Pattern Info

   ${activatorLog}log.info("${cursor}");

Pattern Debug

  ${activatorLog}if(log.isDebugEnabled()){
       log.debug("${cursor}");
  }

Pattern Error

   ${activatorLog}log.error("${cursor}");

Displaying Log

In order to display the debug log, you must add the command line argument "-debug" to your platform.

Two others usefull arguments are "-console" and "-consoleLog".

For more information, read this page : http://www.eclipse.org/eclipse/platform-core/documents/3.1/debug.html

Back to the top