Debugging using the logfile

A handy debugging technique available to any OFBiz Java programmer at any time is to write messages to the OFBiz console log from within your program.

Getting ready

Firstly, ensure the following:

  1. Make sure to import the OFBiz org.ofbiz.base.util.Debug utility into your Java program.
  2. To ensure that your logfile entry is properly marked with the class name and line number from where it was called, check that the Java constant named module is defined within your class file as shown below:
    public static final String module = MyClass.class.getName();
    
  3. If you have turned off console window logging (the default out-of-the-box setting), make sure to return the startup file to its original setting to allow logging to the console window.

How to do it...

To always write to the console window, call the OFBiz Debug utility as shown:

import org.ofbiz.base.util.Debug;
// Code intentionally left out
Debug.log("This is an error message", module);
//Or, if you don't want to write to using the Logger
System.out.println("This is an error message");

How it works...

A call to the org.ofbiz.base.util.Debug method as shown earlier will always write a message to both the error logfile, ofbiz.log and the console window, if it is open.

To write log messages under other conditions, consult the log4J settings and pick the appropriate Debug utility method. For example, to write to the logfile and/or console window only when "Fatal" messages are turned on, you might have a statement such as the following in your code:

Debug.logFatal("Some message", module);

The OFBiz logging facility is an integration of the Apache log4J Java program logging toolkit: http://logging.apache.org/log4j/.

Toggling log settings, that is turning them on or off, is easily accomplished using the WebTools Logging tab, Log Configuration utility.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.176.80