User: oleg    
  Date: 00/10/19 09:05:23

  Modified:    src/main/org/jboss/ejb/plugins LogInterceptor.java
  Log:
  Minor exception logging improvements:
  1) an exceptions wrapped by both TransactionRolledbackException and
  EJBException are now unwrapped for logging
  2) application exception's stack trace is logged as a Debug info if callLogging is 
on.
  
  Revision  Changes    Path
  1.11      +121 -104  jboss/src/main/org/jboss/ejb/plugins/LogInterceptor.java
  
  Index: LogInterceptor.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/jboss/src/main/org/jboss/ejb/plugins/LogInterceptor.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- LogInterceptor.java       2000/09/30 00:59:40     1.10
  +++ LogInterceptor.java       2000/10/19 16:05:22     1.11
  @@ -36,7 +36,7 @@
    *      
    *   @see <related>
    *   @author Rickard �berg ([EMAIL PROTECTED])
  - *   @version $Revision: 1.10 $
  + *   @version $Revision: 1.11 $
    */
   public class LogInterceptor
      extends AbstractInterceptor
  @@ -46,10 +46,10 @@
      // Attributes ----------------------------------------------------
      protected Log log;
      
  -     protected boolean callLogging;
  -     
  -     protected Container container;
  -     
  +    protected boolean callLogging;
  +    
  +    protected Container container;
  +    
      // Static --------------------------------------------------------
   
      // Constructors --------------------------------------------------
  @@ -57,12 +57,12 @@
      // Public --------------------------------------------------------
      public void setContainer(Container container) 
      { 
  -     this.container = container; 
  +    this.container = container; 
      }
  -     
  +    
      public  Container getContainer()
      {
  -     return container;
  +    return container;
      }
   
      // Container implementation --------------------------------------
  @@ -72,10 +72,10 @@
         super.start();
         
         String name = getContainer().getBeanMetaData().getEjbName();
  -             
  -       // Should we log all calls?
  -       callLogging = 
getContainer().getBeanMetaData().getContainerConfiguration().getCallLogging();
  -             
  +        
  +      // Should we log all calls?
  +      callLogging = 
getContainer().getBeanMetaData().getContainerConfiguration().getCallLogging();
  +        
         log = new Log(name);
      }
      
  @@ -84,62 +84,69 @@
      {
         Log.setLog(log);
         
  -             // Log calls?
  -             if (callLogging)
  -             {
  -                     StringBuffer str = new StringBuffer();
  -                     str.append(mi.getMethod().getName());
  -                     str.append("(");
  -                     Object[] args = mi.getArguments();
  -                     if (args != null)
  -                        for (int i = 0; i < args.length; i++)
  -                             {
  -                           str.append(i==0?"":",");
  -                                     str.append(args[i]);
  -                             }
  -                     str.append(")");
  -                     log.log(str.toString());
  -             }
  +        // Log calls?
  +        if (callLogging)
  +        {
  +            StringBuffer str = new StringBuffer();
  +            str.append(mi.getMethod().getName());
  +            str.append("(");
  +            Object[] args = mi.getArguments();
  +            if (args != null)
  +               for (int i = 0; i < args.length; i++)
  +                {
  +                  str.append(i==0?"":",");
  +                    str.append(args[i]);
  +                }
  +            str.append(")");
  +            log.log(str.toString());
  +        }
         
         try
         {
            return getNext().invokeHome(mi);
         } catch (Exception e)
         {
  -             // Log system exceptions
  -             if (e instanceof EJBException)
  -             {
  -                     Logger.error("BEAN EXCEPTION:"+e.getMessage());
  -                     if (((EJBException)e).getCausedByException() != null)
  -                             
Logger.exception(((EJBException)e).getCausedByException());
  -                     
  -                     // Client sees RemoteException
  -                     throw new ServerException("Bean exception. Notify the 
application administrator", e);
  -             } else if (e instanceof RuntimeException)
  -             {
  -                     Logger.error("CONTAINER EXCEPTION:"+e.getMessage());
  -                     Logger.exception(e);
  -                     
  -                     // Client sees RemoteException
  -                     throw new ServerException("Container exception. Notify the 
container developers :-)", e);
  -             } else if (e instanceof TransactionRolledbackException)
  -             {
  -                     Logger.error("TRANSACTION ROLLBACK EXCEPTION:"+e.getMessage());
  -                     // Log the rollback cause
  -                     Logger.exception(((RemoteException)e).detail);
  -                     
  -                     throw e;
  -             } else
  -             {
  -                     // Application exception, or (in case of RemoteException) 
already handled system exc
  -                     // Call debugging -> show exceptions
  -                     if (callLogging)
  -                     {
  -                             Logger.warning(e.getMessage());
  -                     }
  -                     
  -                     throw e;
  -             }
  +        // Log system exceptions
  +        if (e instanceof EJBException)
  +        {
  +            Logger.error("BEAN EXCEPTION:"+e.getMessage());
  +            if (((EJBException)e).getCausedByException() != null)
  +                Logger.exception(((EJBException)e).getCausedByException());
  +            
  +            // Client sees RemoteException
  +            throw new ServerException("Bean exception. Notify the application 
administrator", e);
  +        } else if (e instanceof RuntimeException)
  +        {
  +            Logger.error("CONTAINER EXCEPTION:"+e.getMessage());
  +            Logger.exception(e);
  +            
  +            // Client sees RemoteException
  +            throw new ServerException("Container exception. Notify the container 
developers :-)", e);
  +        } else if (e instanceof TransactionRolledbackException)
  +        {
  +            Logger.error("TRANSACTION ROLLBACK EXCEPTION:"+e.getMessage());
  +            // Log the rollback cause
  +            // Sometimes it wraps EJBException - let's unwrap it
  +            Throwable cause = ((RemoteException) e).detail;
  +            if (cause != null) {
  +                if ((cause instanceof EJBException) &&
  +                        (((EJBException) cause).getCausedByException() != null)) {
  +                    cause = ((EJBException) cause).getCausedByException();
  +                }
  +                Logger.exception(cause);
  +            }
  +            throw e;
  +        } else
  +        {
  +            // Application exception, or (in case of RemoteException) already 
handled system exc
  +            // Call debugging -> show exceptions
  +            if (callLogging)
  +            {
  +                Logger.warning(e.getMessage());
  +            }
  +            
  +            throw e;
  +        }
         } finally
         {
            Log.unsetLog();
  @@ -165,60 +172,70 @@
         // Log calls?
         if (callLogging)
         {
  -             StringBuffer str = new StringBuffer();
  +        StringBuffer str = new StringBuffer();
            str.append(mi.getId() == null ? "" : "["+mi.getId().toString()+"] ");
  -             str.append(mi.getMethod().getName());
  -             str.append("(");
  +        str.append(mi.getMethod().getName());
  +        str.append("(");
            Object[] args = mi.getArguments();
            if (args != null)
               for (int i = 0; i < args.length; i++)
  -                     {
  +            {
                  str.append(i==0?"":",");
  -                             str.append(args[i]);
  -                     }
  -             str.append(")");
  +                str.append(args[i]);
  +            }
  +        str.append(")");
            log.log(str.toString());
         }
  -             
  +        
         try
         {
            return getNext().invoke(mi);
         } catch (Exception e)
         {
  -             // Log system exceptions
  -             if (e instanceof EJBException)
  -             {
  -                     Logger.error("BEAN EXCEPTION:"+e.getMessage());
  -                     if (((EJBException)e).getCausedByException() != null)
  -                             
Logger.exception(((EJBException)e).getCausedByException());
  -                     
  -                     // Client sees RemoteException
  -                     throw new ServerException("Bean exception. Notify the 
application administrator", e);
  -             } else if (e instanceof RuntimeException)
  -             {
  -                     Logger.error("CONTAINER EXCEPTION:"+e.getMessage());
  -                     Logger.exception(e);
  -                     
  -                     // Client sees RemoteException
  -                     throw new ServerException("Container exception. Notify the 
container developers :-)", e);
  -             } else if (e instanceof TransactionRolledbackException)
  -             {
  -                     Logger.error("TRANSACTION ROLLBACK EXCEPTION:"+e.getMessage());
  -                     // Log the rollback cause
  -                     Logger.exception(((RemoteException)e).detail);
  -                     
  -                     throw e;
  -             } else
  -             {
  -                     // Application exception, or (in case of RemoteException) 
already handled system exc
  -                     // Call debugging -> show exceptions
  -                     if (callLogging)
  -                     {
  -                             Logger.warning(e.getMessage());
  -                     }
  -                     
  -                     throw e;
  -             }
  +        // Log system exceptions
  +        if (e instanceof EJBException)
  +        {
  +            Logger.error("BEAN EXCEPTION:"+e.getMessage());
  +            if (((EJBException)e).getCausedByException() != null)
  +                Logger.exception(((EJBException)e).getCausedByException());
  +            
  +            // Client sees RemoteException
  +            throw new ServerException("Bean exception. Notify the application 
administrator", e);
  +        } else if (e instanceof RuntimeException)
  +        {
  +            Logger.error("CONTAINER EXCEPTION:"+e.getMessage());
  +            Logger.exception(e);
  +            
  +            // Client sees RemoteException
  +            throw new ServerException("Container exception. Notify the container 
developers :-)", e);
  +        } else if (e instanceof TransactionRolledbackException)
  +        {
  +            Logger.error("TRANSACTION ROLLBACK EXCEPTION:"+e.getMessage());
  +            // Log the rollback cause
  +            // Sometimes it wraps EJBException - let's unwrap it
  +            Throwable cause = ((RemoteException) e).detail;
  +            if (cause != null) {
  +                if ((cause instanceof EJBException) && 
  +                        (((EJBException) cause).getCausedByException() != null)) {
  +                    cause = ((EJBException) cause).getCausedByException();
  +                }
  +                Logger.exception(cause);
  +            }
  +            throw e;
  +        } else
  +        {
  +            // Application exception, or (in case of RemoteException) already 
handled system exc
  +            // Call debugging -> show exceptions
  +            if (callLogging)
  +            {
  +                Logger.warning(e.getMessage());
  +                // The full stack trace is much more useful for debugging
  +                // On the other hand, it may be turned off by the logger filter
  +                Logger.debug(e);
  +            }
  +            
  +            throw e;
  +        }
         } finally
         {
            Log.unsetLog();
  
  
  

Reply via email to