User: starksm 
  Date: 01/09/11 11:35:02

  Modified:    src/main/org/jboss/logging Log4jService.java Logger.java
  Added:       src/main/org/jboss/logging LoggerFactory.java
                        TracePriority.java
  Removed:     src/main/org/jboss/logging DefaultLog.java Log.java
                        LogStream.java LogToCategory.java LogWriter.java
  Log:
  Convert all logging to org.jboss.logging.Logger which is a subclass of
  org.apache.log4j.Category.
  
  Revision  Changes    Path
  1.12      +3 -53     jboss/src/main/org/jboss/logging/Log4jService.java
  
  Index: Log4jService.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/logging/Log4jService.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- Log4jService.java 2001/09/07 23:22:13     1.11
  +++ Log4jService.java 2001/09/11 18:35:02     1.12
  @@ -14,8 +14,6 @@
   import javax.management.MalformedObjectNameException;
   import javax.management.MBeanRegistration;
   import javax.management.MBeanServer;
  -import javax.management.Notification;
  -import javax.management.NotificationListener;
   import javax.management.ObjectName;
   
   import org.apache.log4j.Category;
  @@ -42,10 +40,10 @@
    * @author <a href="mailto:[EMAIL PROTECTED]";>Scott Stark</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>David Jencks</a>
    * @author <a href="mailto:[EMAIL PROTECTED]";>Jason Dillon</a>
  - * @version $Revision: 1.11 $
  + * @version $Revision: 1.12 $
    */
   public class Log4jService
  -   implements Log4jServiceMBean, NotificationListener, MBeanRegistration
  +   implements Log4jServiceMBean, MBeanRegistration
   {
      /**
       * The default path, either read from system properties or if not set
  @@ -184,53 +182,10 @@
   
      // Public --------------------------------------------------------
      
  -   /**
  -    * This method recevies JMX notification events posted via a Logger
  -    * instances fireNotification method and logs the msg through the
  -    * log4j root Category.
  -    *
  -    * @param n    The log event. This provides the log source as
  -    *             n.getUserData(), the log msg as n.getMessage(), and the
  -    *             type of message from n.getType().
  -    *             
  -    * @see org.jboss.logging.Logger#fireNotification(String,Object,String)
  -    */
  -   public void handleNotification(Notification n, Object handback)
  -   {
  -      if (category == null) return;
  -
  -      String msg = n.getMessage();
  -      char type = n.getType().charAt(0);
  -      String source = (String) n.getUserData();
  -      if (source == null || source.length() == 0) {
  -         source = "Default";
  -      }
  -
  -      // get a category based on the source name, so we can turn on and
  -      // off pieces of logging.
  -      Category localCategory = category.getInstance(source);
  -      switch (type)
  -      {
  -       case 'W':
  -          localCategory.warn(msg);
  -          break;
  -       case 'D':
  -          localCategory.debug(msg);
  -          break;
  -       case 'E':
  -          localCategory.error(msg);
  -          break;
  -       default:
  -          localCategory.info(msg);
  -          break;
  -      }
  -   }
  -
      // --- Begin MBeanRegistration interface methods
      
      /**
  -    * Initializes the MBean by registering as a addNotificationListener of the
  -    * Log service and then invokes start() to configure the log4j framework.
  +    * Invokes start() to configure the log4j framework.
       * 
       * @return the name of this mbean.
       */
  @@ -238,11 +193,6 @@
         throws Exception
      {
         start();
  -      // Receive notification events sent by the Logger mbean
  -      ObjectName logger = new ObjectName(server.getDefaultDomain(),
  -                                         "spine",
  -                                         "Log");
  -      server.addNotificationListener(logger, this, null, null);
         return name == null ? new ObjectName(OBJECT_NAME) : name;
      }
      
  
  
  
  1.13      +61 -111   jboss/src/main/org/jboss/logging/Logger.java
  
  Index: Logger.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss/src/main/org/jboss/logging/Logger.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- Logger.java       2001/09/01 19:50:32     1.12
  +++ Logger.java       2001/09/11 18:35:02     1.13
  @@ -6,142 +6,92 @@
    */
   package org.jboss.logging;
   
  -import java.io.*;
  -import java.net.*;
  -import java.rmi.*;
  -import java.rmi.server.*;
  -import java.util.*;
  -import javax.management.*;
  -
  -/**
  - * @deprecated, As of JBoss 2.3, replaced by the org.apache.log4j framework. TODO 
Example of how to use log4j
  - * @author <a href="mailto:[EMAIL PROTECTED]";>Rickard Öberg</a>
  - * @author <a href="mailto:[EMAIL PROTECTED]";>Scott Stark</a>.
  - * @version $Revision: 1.12 $
  +import org.apache.log4j.Category;
  +import org.apache.log4j.spi.CategoryFactory;
  +
  +/** A custom log4j Category subclass that add a trace level priority.
  + * @see #isTraceEnabled
  + * @see #trace(Object message)
  + * @see #trace(Object, Throwable)
  +
  + * @author [EMAIL PROTECTED]
  + * @version $Revision: 1.13 $
    */
  -public class Logger
  -   extends NotificationBroadcasterSupport
  -   implements LoggerMBean, MBeanRegistration, NotificationBroadcaster, Runnable
  +public class Logger extends Category
   {
      // Constants -----------------------------------------------------
   
      // Attributes ----------------------------------------------------
  -   long sequence = 0;
  -   Date now = new Date();
  -    
  -    boolean running = true;
  -
  -   ArrayList notificationListeners = new ArrayList();
  +   private static CategoryFactory factory = new LoggerFactory();
   
      // Static --------------------------------------------------------
  -   static Logger logger;
  -
  -   public static Logger getLogger() { return logger; }
  -
  -   public static void log(String type, String message)
  -   {
  -      Log l = (Log)Log.getLog();
  -      l.log(type, message);
  -   }
  -
  -   public static void log(String message)
  +   /** This method overrides {@link Category#getInstance} by supplying
  +   its own factory type as a parameter.
  +    @param name, the category name
  +   */
  +   public static Category getInstance(String name)
      {
  -      Log l = (Log)Log.getLog();
  -      l.log(message);
  +      return Category.getInstance(name, factory); 
      }
  -
  -   public static void exception(Throwable exception)
  +   /** This method overrides {@link Category#getInstance} by supplying
  +   its own factory type as a parameter.
  +    @param clazz, the Class whose name will be used as the category name
  +   */
  +   public static Category getInstance(Class clazz)
      {
  -      Log l = (Log)Log.getLog();
  -      l.exception(exception);
  +      return Category.getInstance(clazz.getName(), factory); 
      }
   
  -   public static void warning(String message)
  +   /** Create a Logger instance given the category name.
  +    @param name, the category name
  +    */
  +   public static Logger create(String name)
      {
  -      Log l = (Log)Log.getLog();
  -      l.warning(message);
  +      Logger logger = (Logger) Category.getInstance(name, factory);
  +      return logger;
      }
  -    
  -   public static void debug(String message)
  +   /** Create a Logger instance given the category class. This simply
  +    calls create(clazz.getName()).
  +    @param clazz, the Class whose name will be used as the category name
  +    */
  +   public static Logger create(Class clazz)
      {
  -      Log l = (Log)Log.getLog();
  -      l.debug(message);
  +      Logger logger = (Logger) Category.getInstance(clazz.getName(), factory);
  +      return logger;
      }
   
  -   public static void debug(Throwable exception)
  +  // Constructors --------------------------------------------------
  +   /** Creates new JBossCategory with the given category name.
  +    @param name, the category name.
  +   */
  +   public Logger(String name)
      {
  -      Log l = (Log)Log.getLog();
  -      l.debug(exception);
  +      super(name);
      }
  -
  -   public static void error(String message)
  -   {
  -      Log l = (Log) Log.getLog();
  -      l.error(message);
  -  }
  -
   
  -   public static void error(Throwable exception)
  +   /** Check to see if the TRACE priority is enabled for this category.
  +   @return true if a {@link #trace(String)} method invocation would pass
  +   the msg to the configured appenders, false otherwise.
  +   */
  +   public boolean isTraceEnabled()
      {
  -      Log l = (Log) Log.getLog();
  -      l.error(exception.toString());
  -  }
  -
  -   // Constructors --------------------------------------------------
  -   public Logger()
  -   {
  -      logger = this;
  -        
  -        Thread runner = new Thread(this, "Log time updater");
  -        runner.setDaemon(true);
  -        runner.start();
  +      if( hierarchy.isDisabled(TracePriority.TRACE_INT) )
  +         return false;
  +      return TracePriority.TRACE.isGreaterOrEqual(this.getChainedPriority());
      }
   
  -   // Public --------------------------------------------------------
  -   public synchronized void fireNotification(String type, Object source, String 
message)
  +   /** Issue a log msg with a priority of TRACE.
  +   Invokes super.log(TracePriority.TRACE, message);
  +   */
  +   public void trace(Object message)
      {
  -       //AS FIXME Just a hack (now.getTime())
  -       Notification n = new Notification(type, this, sequence++, now.getTime(), 
message);
  -      n.setUserData(source);
  -
  -      sendNotification(n);
  +      super.log(TracePriority.TRACE, message);
      }
  -
  -   // MBeanRegistration implementation ------------------------------
  -   public ObjectName preRegister(MBeanServer server, ObjectName name)
  -      throws java.lang.Exception
  +   /** Issue a log msg and throwable with a priority of TRACE.
  +   Invokes super.log(TracePriority.TRACE, message, t);
  +   */
  +   public void trace(Object message, Throwable t)
      {
  -      return name == null ? new ObjectName("JBOSS-SYSTEM:spine=Log") : name;
  +      super.log(TracePriority.TRACE, message, t);
      }
  -
  -   public void postRegister(java.lang.Boolean registrationDone)
  -   {
  -   }
  -
  -   public void preDeregister()
  -      throws java.lang.Exception
  -   {}
  -
  -   public void postDeregister()
  -    {
  -        running = false;
  -    }
  -
  -   // Runnable implementation ---------------------------------------
  -    public void run()
  -    {
  -        while (running)
  -        {
  -            now.setTime(System.currentTimeMillis());
  -        
  -            try
  -            {
  -                Thread.sleep(5*1000);
  -            } catch (InterruptedException e)
  -            {
  -                // Ignore
  -            }
  -        }
  -    }
   }
  -
  
  
  
  1.1                  jboss/src/main/org/jboss/logging/LoggerFactory.java
  
  Index: LoggerFactory.java
  ===================================================================
  /*
   * JBoss, the OpenSource J2EE webOS
   *
   * Distributable under LGPL license.
   * See terms of license at gnu.org.
   */
  package org.jboss.logging;
  
  import org.apache.log4j.Category;
  import org.apache.log4j.spi.CategoryFactory;
  
  /** A custom category factory that returns Logger instaneces
   * @author [EMAIL PROTECTED]
   * @version $Revision: 1.1 $
   */
  public class LoggerFactory implements CategoryFactory
  {
     public Category makeNewCategoryInstance(String name)
     {
        return new Logger(name);
     }
  }
  
  
  
  1.1                  jboss/src/main/org/jboss/logging/TracePriority.java
  
  Index: TracePriority.java
  ===================================================================
  /*
  * JBoss, the OpenSource J2EE webOS
  *
  * Distributable under LGPL license.
  * See terms of license at gnu.org.
  */
  package org.jboss.logging;
  
  import org.apache.log4j.Priority;
  
  /** Adds a trace priority that is below the standard log4j DEBUG priority.
   This is a custom priority that is 100 below the Priority.DEBUG_INT and
   represents a lower priority useful for logging events that should only
   be displayed when deep debugging is required.
   
   @see org.apache.log4j.Category
   @see org.apache.log4j.Priority
   
   @author [EMAIL PROTECTED]
   @version $Revision: 1.1 $
   */
  public class TracePriority extends Priority
  {
    // Constants -----------------------------------------------------
     /** The integer representation of the priority, (Priority.DEBUG_INT - 100) */
     public static final int TRACE_INT = Priority.DEBUG_INT - 100;
     /** The TRACE priority object singleton */
     public static final TracePriority TRACE = new TracePriority(TRACE_INT, "TRACE");
    
    // Attributes ----------------------------------------------------
  
    // Static --------------------------------------------------------
     /** Convert an integer passed as argument to a priority. If the conversion
      fails, then this method returns the specified default.
      @return the Priority object for name if one exists, defaultPriority otherwize.
      */
     public static Priority toPriority(String name, Priority defaultPriority)
     {
        if( name == null )
           return TRACE;
        
        Priority p = TRACE;
        if( name.charAt(0) != 'T' )
           p = Priority.toPriority(name, defaultPriority);
        return p;
     }
     /** Convert an integer passed as argument to a priority. If the conversion
      fails, then this method returns the specified default.
      @return the Priority object for i if one exists, defaultPriority otherwize.
      */
     public static Priority toPriority(int i, Priority defaultPriority)
     {
        Priority p;
        if( i == TRACE_INT )
           p = TRACE;
        else
           p = Priority.toPriority(i);
        return p;
     }
  
    // Constructors --------------------------------------------------
     protected TracePriority(int level, String strLevel)
     {
        super(level, strLevel, 7);
     }
     
  }
  
  
  

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

Reply via email to