AnsweredAssumed Answered

Tool (Import, Export) dont use LOG4J and invoke System.exit

Question asked by sbroussi on May 29, 2006
Latest reply on May 30, 2006 by davidc

I've noticed that the abstract class does not use the LOG4J framework, but use "System.out" and "exception.printStackTrace()".

Moreover, the Tool class ends with System.exit(0) or System.exit(-1).

This is not so "extensible" like ALL your other services  :wink:

I propose that the Tool class:
- use the "log4j" framework
- do not invoke System.exit(..)
- let the exception be thrown outside the method to be caught by the default JVM exception handler or by a wrapper class as in this example:

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

* This class is a "wrapper" to:
* - log errors using log4j
* - return a "exit code" different from 0 when one error occurs.
public final class ImportWrapper
   protected static Log logger = LogFactory.getLog(ImportWrapper.class);
   public static void main(String[] args)
      logger.debug("Start of import");
      int exitCode = 1;

         // OK
         exitCode = 0;
      catch (Throwable t)
         logger.error("ERROR DURING IMPORT:" + t.getMessage(), t);
      logger.debug("End of import - exitCode=" + exitCode);