User: stacycurl
  Date: 01/03/29 09:47:47

  Modified:    src/main/org/jboss/logging Log.java
  Log:
  Log.createLog checks an environment property JBOSS_LOG_CLASS and
  instantiates that class, if JBOSS_LOG_CLASS is missing it reverts back to the
  previous behaviour of creating org.jboss.logging.DefaultLog
  
  Revision  Changes    Path
  1.8       +61 -47    jboss/src/main/org/jboss/logging/Log.java
  
  Index: Log.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/logging/Log.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- Log.java  2000/12/08 17:41:31     1.7
  +++ Log.java  2001/03/29 17:47:47     1.8
  @@ -14,25 +14,29 @@
   import javax.management.*;
   
   /**
  - *      
  + *
    *   @see <related>
    *   @author Rickard �berg ([EMAIL PROTECTED])
  - *   @version $Revision: 1.7 $
  + *   @version $Revision: 1.8 $
    */
   public abstract class Log
   {
      // Constants -----------------------------------------------------
  -    
  +   private static final String m_sInformation = "Information";
  +   private static final String m_sDebug = "Debug";
  +   private static final String m_sWarning = "Warning";
  +   private static final String m_sError = "Error";
  +
      // Attributes ----------------------------------------------------
      long count = 0;
  -   
  +
      Date now = new Date();
  -   
  +
      Object source = null;
  -   
  +
      // Static --------------------------------------------------------
   //   static ThreadLocal currentLog = new ThreadLocal();
  -   
  +
      static ThreadLocal currentLog = new InheritableThreadLocal()
      {
                // Child threads should get same stack, but only a copy of it
  @@ -40,13 +44,13 @@
                {
                        if (obj != null)
                                return ((Stack)obj).clone();
  -                     else    
  +                     else
                                return null;
                }
      };
  -      
  +
         protected static Log defaultLog;
  -   
  +
      public static void setLog(Log log)
      {
         Stack s;
  @@ -60,7 +64,7 @@
            s.push(log);
         }
      }
  -   
  +
      public static void unsetLog()
      {
         if (currentLog.get() != null)
  @@ -71,7 +75,7 @@
               currentLog.set(null);
         }
      }
  -   
  +
      public static Log getLog()
      {
         Stack s = (Stack)currentLog.get();
  @@ -85,11 +89,13 @@
                                return (Log)s.peek();
                        }
      }
  -      
  +
         public static Log createLog( Object pSource ) {
                 Log lReturn;
                try {
  -                     Class lLog = 
Thread.currentThread().getContextClassLoader().loadClass( 
"org.jboss.logging.DefaultLog" );
  +            final String logClass = System.getProperty("JBOSS_LOG_CLASS", 
"org.jboss.logging.DefaultLog");
  +
  +                     Class lLog = 
Thread.currentThread().getContextClassLoader().loadClass( logClass );
   //AS                 Class lLog = Class.forName( "org.jboss.logging.DefaultLog" );
                        lReturn = (Log) lLog.getConstructor( new Class[] { 
Object.class } ).newInstance(
                                new Object[] { pSource }
  @@ -100,81 +106,89 @@
                }
                return lReturn;
         }
  -   
  +
      // Constructors --------------------------------------------------
      public Log()
      {
         this("Default");
      }
  -   
  +
      public Log(Object source)
      {
         this.source = source;
      }
  -   
  +
      // Public --------------------------------------------------------
      public abstract void log(String type, String message);
  -   
  +
      public synchronized void log(String message)
      {
  -      log("Information", message);
  +      log(m_sInformation, message);
      }
  -   
  +
      public synchronized void error(String message)
      {
  -      log("Error", message);
  +      log(m_sError, message);
      }
  -   
  +
      public synchronized void warning(String message)
      {
  -      log("Warning", message);
  -   }   
  -   
  +      log(m_sWarning, message);
  +   }
  +
      public synchronized void debug(String message)
  +   {
  +      log(m_sDebug, message);
  +   }
  +
  +   public synchronized void log(Throwable exception)
  +   {
  +      logException(m_sInformation, exception);
  +   }
  +
  +   public synchronized void error(Throwable exception)
      {
  -      log("Debug", message);
  -   }   
  -   
  +      logException(m_sError, exception);
  +   }
  +
      public synchronized void exception(Throwable exception)
      {
  -      ByteArrayOutputStream baos = new ByteArrayOutputStream();
  -      PrintStream out = new PrintStream(baos);
  -      exception.printStackTrace(out);
  -      out.close();
  -      
  -      DataInputStream din = new DataInputStream(new 
ByteArrayInputStream(baos.toByteArray()));
  -      
  -      String error;
  -      try
  -      {
  -         while((error = din.readLine()) != null)
  -            log("Error", error);
  -      } catch (Exception e) {}
  +      error(exception);
  +   }
  +
  +   public synchronized void warning(Throwable exception)
  +   {
  +      logException(m_sWarning, exception);
      }
  -   
  +
      public synchronized void debug(Throwable exception)
      {
  +      logException(m_sDebug, exception);
  +   }
  +
  +   protected synchronized void logException(final String categoryString, Throwable 
exception)
  +   {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         PrintStream out = new PrintStream(baos);
         exception.printStackTrace(out);
         out.close();
  -      
  +
         DataInputStream din = new DataInputStream(new 
ByteArrayInputStream(baos.toByteArray()));
  -      
  +
         String error;
         try
         {
            while((error = din.readLine()) != null)
  -            log("Debug", error);
  +            log(categoryString, error);
         } catch (Exception e) {}
      }
  -   
  +
      // Private -------------------------------------------------------
      private long nextCount()
      {
         return count++;
      }
  -      
  +
         public static class NoLog extends Log {
                 public NoLog() {
                         super();
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to