User: starksm 
  Date: 01/11/20 01:42:54

  Modified:    src/main/org/jboss/logging Tag: Branch_2_4 Log4jService.java
                        Logger.java
  Removed:     src/main/org/jboss/logging Tag: Branch_2_4
                        ConsoleLogging.java ConsoleLoggingMBean.java
                        DefaultLog.java FileLogging.java
                        FileLoggingMBean.java Log.java LogStream.java
                        LogToCategory.java LogWriter.java
                        ViewerLogging.java ViewerLoggingMBean.java
  Log:
  Change to the unified log4j based org.jboss.logging.Logger class.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.7.2.1   +3 -57     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.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- Log4jService.java 2001/06/15 18:00:17     1.7
  +++ Log4jService.java 2001/11/20 09:42:53     1.7.2.1
  @@ -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;
  @@ -27,22 +25,13 @@
   1., It initalizes the log4j framework from the log4j properties format file
       specified by the ConfigurationPath attribute to that the log4j may be
       used by JBoss components.
  -2., It collects JMX notification events fired by the "service=Log" mbean
  -    and logs the msgs to log4j. This allows the Log4jService
  -    to replace all other JBoss logging services like ConsoleLogging and
  -    FileLogging.
  -    
  -3,  It uses the log name as the category to log under, allowing you to turn 
  -    individual components on and off using the log4j configuration file
  -    (automatically reloaded frequently).
   
   @author <a href="mailto:[EMAIL PROTECTED]";>Fulco Muriglio</a>
  -@author [EMAIL PROTECTED]
  +@author [EMAIL PROTECTED]
   @author <a href="mailto:[EMAIL PROTECTED]";>David Jencks</a>
  -@version $Revision: 1.7 $
  +@version $Revision: 1.7.2.1 $
   */
  -public class Log4jService implements Log4jServiceMBean, NotificationListener,
  -    MBeanRegistration
  +public class Log4jService implements Log4jServiceMBean, MBeanRegistration
   {
   
   // Attributes ----------------------------------------------------
  @@ -141,55 +130,12 @@
               category.info("Stopped Log4jService");
       }
   
  -// 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.
  -    @return the name of this mbean.
  -    */
       public ObjectName preRegister(MBeanServer server, ObjectName name) throws 
Exception
       {
           start();
  -        // Receive notification events sent by the Logger mbean
           ObjectName logger = new 
ObjectName(server.getDefaultDomain(),"service","Log");
  -        server.addNotificationListener(logger,this,null,null);
           return name == null ? new ObjectName(OBJECT_NAME) : name;
       }
       public void postRegister(Boolean b)
  
  
  
  1.8.4.1   +188 -133  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.8
  retrieving revision 1.8.4.1
  diff -u -r1.8 -r1.8.4.1
  --- Logger.java       2001/04/24 23:24:24     1.8
  +++ Logger.java       2001/11/20 09:42:54     1.8.4.1
  @@ -1,147 +1,202 @@
   /*
  - * JBoss, the OpenSource EJB server
  + * JBoss, the OpenSource J2EE webOS
    *
    * Distributable under LGPL license.
    * See terms of license at gnu.org.
    */
   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
  - * @author Rickard �berg ([EMAIL PROTECTED])
  - * @author [EMAIL PROTECTED]
  - * @version $Revision: 1.8 $
  +import org.apache.log4j.Category;
  +import org.apache.log4j.Priority;
  +
  +/** A custom log4j Category wrapper that adds a trace level priority and only
  + exposes the relevent factory and logging methods.
  +
  + * @see #isTraceEnabled
  + * @see #trace(Object message)
  + * @see #trace(Object, Throwable)
  +
  + * @author [EMAIL PROTECTED]
  + * @version $Revision: 1.8.4.1 $
    */
   public class Logger
  -   extends NotificationBroadcasterSupport
  -   implements LoggerMBean, MBeanRegistration, NotificationBroadcaster, Runnable
   {
      // Constants -----------------------------------------------------
  -    
  +
      // Attributes ----------------------------------------------------
  -   long sequence = 0;
  -   Date now = new Date();
  -     
  -     boolean running = true;
  -   
  -   ArrayList notificationListeners = new ArrayList();
  -   
  +   private Category log;
  +
      // 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)
  -   {
  -      Log l = (Log)Log.getLog();
  -      l.log(message);
  -   }
  -
  -   public static void exception(Throwable exception)
  -   {
  -      Log l = (Log)Log.getLog();
  -      l.exception(exception);
  -   }
  -
  -   public static void warning(String message)
  -   {
  -      Log l = (Log)Log.getLog();
  -      l.warning(message);
  -   }
  -     
  -   public static void debug(String message)
  -   {
  -      Log l = (Log)Log.getLog();
  -      l.debug(message);
  -   }
  -
  -   public static void debug(Throwable exception)
  -   {
  -      Log l = (Log)Log.getLog();
  -      l.debug(exception);
  -   }
  -   
  -   public static void error(String message) 
  -   {
  -       Log l = (Log) Log.getLog();
  -       l.error(message);
  -  }
  -  
  -  
  -   public static void error(Throwable exception) 
  -   {
  -       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();
  -   }
  -   
  -   // Public --------------------------------------------------------
  -   public synchronized void fireNotification(String type, Object source, String 
message)
  -   {
  -       //AS FIXME Just a hack (now.getTime())
  -        Notification n = new Notification(type, this, sequence++, now.getTime(), 
message);
  -      n.setUserData(source);
  -    
  -      sendNotification(n);
  -   }
  -   
  -   // MBeanRegistration implementation ------------------------------
  -   public ObjectName preRegister(MBeanServer server, ObjectName name)
  -      throws java.lang.Exception
  -   {
  -      return name == null ? new ObjectName("DefaultDomain:service=Log") : name;
  -   }
  -   
  -   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
  -                     }
  -             }
  -     }
  -}
   
  +   /** Create a Logger instance given the category name.
  +    @param name, the category name
  +    */
  +   public static Logger getLogger(String name)
  +   {
  +      Logger logger = new Logger(name);
  +      return logger;
  +   }
  +   /** 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 getLogger(Class clazz)
  +   {
  +      Logger logger = new Logger(clazz.getName());
  +      return logger;
  +   }
  +
  +  // Constructors --------------------------------------------------
  +   /** Creates new JBossCategory with the given category name.
  +    @param name, the category name.
  +   */
  +   protected Logger(String name)
  +   {
  +      log = Category.getInstance(name);
  +   }
  +
  +   public Category getCategory()
  +   {
  +      return log;
  +   }
  +
  +   /** 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()
  +   {
  +      if( log.isEnabledFor(TracePriority.TRACE) == false )
  +         return false;
  +      return TracePriority.TRACE.isGreaterOrEqual(log.getChainedPriority());
  +   }
  +
  +   /** Issue a log msg with a priority of TRACE.
  +   Invokes log.log(TracePriority.TRACE, message);
  +   */
  +   public void trace(Object message)
  +   {
  +      log.log(TracePriority.TRACE, message);
  +   }
  +   /** Issue a log msg and throwable with a priority of TRACE.
  +   Invokes log.log(TracePriority.TRACE, message, t);
  +   */
  +   public void trace(Object message, Throwable t)
  +   {
  +      log.log(TracePriority.TRACE, message, t);
  +   }
  +
  +   /** 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 isDebugEnabled()
  +   {
  +      Priority p = Priority.DEBUG;
  +      if( log.isEnabledFor(p) == false )
  +         return false;
  +      return p.isGreaterOrEqual(log.getChainedPriority());
  +   }
  +
  +   /** Issue a log msg with a priority of DEBUG.
  +   Invokes log.log(Priority.DEBUG, message);
  +   */
  +   public void debug(Object message)
  +   {
  +      log.log(Priority.DEBUG, message);
  +   }
  +   /** Issue a log msg and throwable with a priority of DEBUG.
  +   Invokes log.log(Priority.DEBUG, message, t);
  +   */
  +   public void debug(Object message, Throwable t)
  +   {
  +      log.log(Priority.DEBUG, message, t);
  +   }
  +
  +   /** Check to see if the INFO priority is enabled for this category.
  +   @return true if a {@link #info(String)} method invocation would pass
  +   the msg to the configured appenders, false otherwise.
  +   */
  +   public boolean isInfoEnabled()
  +   {
  +      Priority p = Priority.INFO;
  +      if( log.isEnabledFor(p) == false )
  +         return false;
  +      return p.isGreaterOrEqual(log.getChainedPriority());
  +   }
  +
  +   /** Issue a log msg with a priority of INFO.
  +   Invokes log.log(Priority.INFO, message);
  +   */
  +   public void info(Object message)
  +   {
  +      log.log(Priority.INFO, message);
  +   }
  +   /** Issue a log msg and throwable with a priority of INFO.
  +   Invokes log.log(Priority.INFO, message, t);
  +   */
  +   public void info(Object message, Throwable t)
  +   {
  +      log.log(Priority.INFO, message, t);
  +   }
  +
  +   /** Issue a log msg with a priority of WARN.
  +   Invokes log.log(Priority.WARN, message);
  +   */
  +   public void warn(Object message)
  +   {
  +      log.log(Priority.WARN, message);
  +   }
  +   /** Issue a log msg and throwable with a priority of WARN.
  +   Invokes log.log(Priority.WARN, message, t);
  +   */
  +   public void warn(Object message, Throwable t)
  +   {
  +      log.log(Priority.WARN, message, t);
  +   }
  +
  +   /** Issue a log msg with a priority of ERROR.
  +   Invokes log.log(Priority.ERROR, message);
  +   */
  +   public void error(Object message)
  +   {
  +      log.log(Priority.ERROR, message);
  +   }
  +   /** Issue a log msg and throwable with a priority of ERROR.
  +   Invokes log.log(Priority.ERROR, message, t);
  +   */
  +   public void error(Object message, Throwable t)
  +   {
  +      log.log(Priority.ERROR, message, t);
  +   }
  +
  +   /** Issue a log msg with a priority of FATAL.
  +   Invokes log.log(Priority.FATAL, message);
  +   */
  +   public void fatal(Object message)
  +   {
  +      log.log(Priority.FATAL, message);
  +   }
  +   /** Issue a log msg and throwable with a priority of FATAL.
  +   Invokes log.log(Priority.FATAL, message, t);
  +   */
  +   public void fatal(Object message, Throwable t)
  +   {
  +      log.log(Priority.FATAL, message, t);
  +   }
  +
  +   /** Issue a log msg with the given priority.
  +   Invokes log.log(p, message);
  +   */
  +   public void log(Priority p, Object message)
  +   {
  +      log.log(p, message);
  +   }
  +   /** Issue a log msg with the given priority.
  +   Invokes log.log(p, message, t);
  +   */
  +   public void log(Priority p, Object message, Throwable t)
  +   {
  +      log.log(p, message, t);
  +   }
  +}
  
  
  

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

Reply via email to