You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by js...@apache.org on 2002/08/28 17:27:29 UTC

cvs commit: jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet MessageDrivenObjectSupport.java

jstrachan    2002/08/28 08:27:29

  Modified:    messenger/src/java/org/apache/commons/messagelet
                        MessageDrivenObjectSupport.java
  Log:
  Removed the use of System.out.println() in cases where there is no ServletContext initialized as yet.
  
  Now commons-logging is used instead.
  
  In addition there's now a helper method getLog() which can be used for logging from inside an MDO with a far better API than the simple servlet-style log(String).
  
  e.g.
  
  if ( getLog().isDebugEnabled() ) {
  	getLog().debug( "some debugging: " + something );
  }
  getLog().warn( "this is a warning" );
  getLog().error( "some error", exception );
  
  Revision  Changes    Path
  1.4       +21 -4     jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/MessageDrivenObjectSupport.java
  
  Index: MessageDrivenObjectSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/messenger/src/java/org/apache/commons/messagelet/MessageDrivenObjectSupport.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MessageDrivenObjectSupport.java	17 May 2002 15:05:46 -0000	1.3
  +++ MessageDrivenObjectSupport.java	28 Aug 2002 15:27:29 -0000	1.4
  @@ -13,6 +13,9 @@
   import javax.servlet.ServletContext;
   import javax.servlet.ServletException;
   
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
  +
   /** <p><code>MessageDrivenObjectSupport</code> is an abstract base
     * class for implementing your own MessageDrivenObject instance
     * with some useful implementation level methods.</p>
  @@ -22,6 +25,10 @@
     */
   public abstract class MessageDrivenObjectSupport implements MessageDrivenObject {
   
  +    
  +    /** The Log to which logging calls will be made. */
  +    private Log log = LogFactory.getLog( getClass() );
  +    
       /**
        * The ServletContext with which this dispatcher is associated.
        */
  @@ -59,11 +66,20 @@
       
       // Implementation methods
       //-------------------------------------------------------------------------        
  +
  +    /**
  +     * Provides access to a logger which can use JDK 1.4 logging, log4j or logkit 
  +     * under the covers.
  +     */
  +    protected Log getLog() {
  +        return log;
  +    }
       
       /** Logs a message to the current ServletContext */
       protected void log( String message ) {
           if ( context == null ) {
  -            System.out.println( "No ServletContext yet: " + message );
  +            log.error( "No Servletcontext available so cannot use it for logging" );
  +            log.info( message );
           }
           else {
               context.log( message );
  @@ -73,7 +89,8 @@
       /** Logs a message and exception the current ServletContext */
       protected void log( String message, Throwable t) {
           if ( context == null ) {
  -            System.out.println( "No ServletContext yet: " + message );
  +            log.error( "No Servletcontext available so cannot use it for logging" );
  +            log.error( message, t );
           }
           else {
               context.log( message, t );
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>