wiki:GritsLogging

Logging in GRITS toolbox

Since GRITS toolbox is a stand-alone application that can run on several different computers with different operation systems and configuration logging or errors and unexpected states in the application is essential for debugging. GRITS uses Log4j as a convenient logging framework.

How to log

All classes for log4j can be found in the org.apache bundle, which needs to added as a dependency. In any class that needs to log create a static member variable (replace ClassX with the name of the class):

private static final Logger logger = Logger.getLogger(ClassX.class);

Now the logger can be used at any place in the class:

logger.info(PLUGIN_ID + " END");

Logging strategy

The following rules should be kept in mind when writing program code:

  1. Any action or command should start with a log message and end with a log message (DEBUG)
  2. (optional) Any method call inside a plugin should write a info log message (INFO)
  3. Any caught exception should be logged except if the exception is write in another exception and thrown to the caller class
  4. Any action or command should start and end with a try/catch construct ( + see point 3.)

Logging configuration

Because of the problems caused by log4j.properties, the Eclipse plugin architecture and the availability of the file in the different class-loaders of plugins the configuration is currently hard coded in Java. The method for configuring the logger is called as part of the start method of the Activator class of the main Plugin. The source code can be found in class SimianToolsLog (Package:edu.uga.ccrc.simiantools.log; Main plugin).

Logging format

The following log4j logging pattern is used in the application: %d{yyyy-MM-dd HH:mm:ss} %p %m [%C %M %L] %n

Logging location

Deployment: Log files can be found in the following sub-folder of the installation folder: GRITS\configuration\edu.uga.ccrc.simiantools\log

Eclipse: Log files of the project running in Eclipse can be found in the sub-folder of the Eclipse workspace folder: .metadata\.plugins\org.eclipse.pde.core\SimianTools.product\edu.uga.ccrc.simiantools\log. Please note that SimianTools.product is the name of the product file that is executed.

Logging to console

For some reason, if one wants to see the log information in the console (also see #142) one can get this fragment org.grits.toolbox.fragment.developers from the svn as a Fragment Project into one's workspace. After creating this project from the svn one needs to add this fragment to the product file in its Dependency Tab. Also one has to add the required dependencies (see images below).


Figure 1



Figure 2

For working of this fragment and more information, please look here.

Last modified 8 years ago Last modified on 11/19/2014 12:16:17 AM

Attachments (2)

Download all attachments as: .zip