[jboss-svn-commits] JBoss Common SVN: r2438 - common-logging-log4j/trunk/src/main/java/org/jboss/logging/log4j.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jul 9 17:30:31 EDT 2007


Author: jason.greene at jboss.com
Date: 2007-07-09 17:30:31 -0400 (Mon, 09 Jul 2007)
New Revision: 2438

Added:
   common-logging-log4j/trunk/src/main/java/org/jboss/logging/log4j/Log4jMDCProvider.java
   common-logging-log4j/trunk/src/main/java/org/jboss/logging/log4j/Log4jNDCProvider.java
Modified:
   common-logging-log4j/trunk/src/main/java/org/jboss/logging/log4j/Log4jLoggerPlugin.java
Log:
Log4j implementation of NDC/MDC - JBCOMMON-28


Modified: common-logging-log4j/trunk/src/main/java/org/jboss/logging/log4j/Log4jLoggerPlugin.java
===================================================================
--- common-logging-log4j/trunk/src/main/java/org/jboss/logging/log4j/Log4jLoggerPlugin.java	2007-07-09 21:26:36 UTC (rev 2437)
+++ common-logging-log4j/trunk/src/main/java/org/jboss/logging/log4j/Log4jLoggerPlugin.java	2007-07-09 21:30:31 UTC (rev 2438)
@@ -27,7 +27,10 @@
 import org.apache.log4j.Priority;
 import org.jboss.logging.Logger;
 import org.jboss.logging.LoggerPlugin;
-import org.jboss.logging.XLevel;
+import org.jboss.logging.MDCProvider;
+import org.jboss.logging.MDCSupport;
+import org.jboss.logging.NDCProvider;
+import org.jboss.logging.NDCSupport;
 
 /**
  * Delegate for org.jboss.logging.Logger logging to log4j. Body of implementation
@@ -37,35 +40,36 @@
  * @see org.jboss.logging.LoggerPlugin
  *
  * @author  <a href="mailto:sacha.labourey at cogito-info.ch">Sacha Labourey</a>.
+ * @author Jason T. Greene
  * @version $Revision$
  */
-public class Log4jLoggerPlugin implements LoggerPlugin
+public class Log4jLoggerPlugin implements LoggerPlugin, NDCSupport, MDCSupport
 {
-   
+
    // Constants -----------------------------------------------------
 
-   /** 
+   /**
     *  Fully qualified classname for this class so Log4J locationinfo will be
     *  correct
     */
    private static final String FQCN = Logger.class.getName();
-   
+
    // Attributes ----------------------------------------------------
-   
+
    /** The Log4j delegate logger. */
    private transient org.apache.log4j.Logger log;
 
    // Static --------------------------------------------------------
-   
+
    // Constructors --------------------------------------------------
-   
+
    public Log4jLoggerPlugin () { }
-   
+
    public void init (String name)
    {
       log = LogManager.getLogger(name);
    }
-   
+
    // Public --------------------------------------------------------
 
    public Category getCategory()
@@ -80,18 +84,18 @@
    {
       return log;
    }
-   
+
    // LoggerPlugin implementation ----------------------------------------------
-   
+
    public boolean isTraceEnabled()
-   {      
+   {
       Level l = Level.TRACE;
       if (log.isEnabledFor(l) == false)
          return false;
       return l.isGreaterOrEqual(log.getEffectiveLevel());
    }
 
-   /** 
+   /**
     * Issue a log msg with a level of TRACE.
     * Invokes log.log(Level.TRACE, message);
     */
@@ -100,7 +104,7 @@
       log.log(FQCN, Level.TRACE, message, null);
    }
 
-   /** 
+   /**
     * Issue a log msg and throwable with a level of TRACE.
     * Invokes log.log(Level.TRACE, message, t);
     */
@@ -123,7 +127,7 @@
       return l.isGreaterOrEqual(log.getEffectiveLevel());
    }
 
-   /** 
+   /**
     * Issue a log msg with a level of DEBUG.
     * Invokes log.log(Level.DEBUG, message);
     */
@@ -132,7 +136,7 @@
       log.log(FQCN, Level.DEBUG, message, null);
    }
 
-   /** 
+   /**
     * Issue a log msg and throwable with a level of DEBUG.
     * Invokes log.log(Level.DEBUG, message, t);
     */
@@ -141,7 +145,7 @@
       log.log(FQCN, Level.DEBUG, message, t);
    }
 
-   /** 
+   /**
     * Check to see if the INFO level is enabled for this logger.
     *
     * @return true if a {@link #info(Object)} method invocation would pass
@@ -155,7 +159,7 @@
       return l.isGreaterOrEqual(log.getEffectiveLevel());
    }
 
-   /** 
+   /**
     * Issue a log msg with a level of INFO.
     * Invokes log.log(Level.INFO, message);
     */
@@ -173,7 +177,7 @@
       log.log(FQCN, Level.INFO, message, t);
    }
 
-   /** 
+   /**
     * Issue a log msg with a level of WARN.
     * Invokes log.log(Level.WARN, message);
     */
@@ -182,7 +186,7 @@
       log.log(FQCN, Level.WARN, message, null);
    }
 
-   /** 
+   /**
     * Issue a log msg and throwable with a level of WARN.
     * Invokes log.log(Level.WARN, message, t);
     */
@@ -191,7 +195,7 @@
       log.log(FQCN, Level.WARN, message, t);
    }
 
-   /** 
+   /**
     * Issue a log msg with a level of ERROR.
     * Invokes log.log(Level.ERROR, message);
     */
@@ -200,7 +204,7 @@
       log.log(FQCN, Level.ERROR, message, null);
    }
 
-   /** 
+   /**
     * Issue a log msg and throwable with a level of ERROR.
     * Invokes log.log(Level.ERROR, message, t);
     */
@@ -209,7 +213,7 @@
       log.log(FQCN, Level.ERROR, message, t);
    }
 
-   /** 
+   /**
     * Issue a log msg with a level of FATAL.
     * Invokes log.log(Level.FATAL, message);
     */
@@ -218,7 +222,7 @@
       log.log(FQCN, Level.FATAL, message, null);
    }
 
-   /** 
+   /**
     * Issue a log msg and throwable with a level of FATAL.
     * Invokes log.log(Level.FATAL, message, t);
     */
@@ -227,7 +231,7 @@
       log.log(FQCN, Level.FATAL, message, t);
    }
 
-   /** 
+   /**
     * Issue a log msg with the given level.
     * Invokes log.log(p, message);
     *
@@ -238,7 +242,7 @@
       log.log(FQCN, p, message, null);
    }
 
-   /** 
+   /**
     * Issue a log msg with the given priority.
     * Invokes log.log(p, message, t);
     *
@@ -249,7 +253,7 @@
       log.log(FQCN, p, message, t);
    }
 
-   /** 
+   /**
     * Issue a log msg with the given level.
     * Invokes log.log(l, message);
     */
@@ -258,7 +262,7 @@
       log.log(FQCN, l, message, null);
    }
 
-   /** 
+   /**
     * Issue a log msg with the given level.
     * Invokes log.log(l, message, t);
     */
@@ -267,14 +271,24 @@
       log.log(FQCN, l, message, t);
    }
 
+   public NDCProvider getNDCProvider()
+   {
+      return new Log4jNDCProvider();
+   }
+
+   public MDCProvider getMDCProvider()
+   {
+      return new Log4jMDCProvider();
+   }
+
    // Y overrides ---------------------------------------------------
-   
+
    // Package protected ---------------------------------------------
-   
+
    // Protected -----------------------------------------------------
-   
+
    // Private -------------------------------------------------------
-   
+
    // Inner classes -------------------------------------------------
-   
+
 }

Added: common-logging-log4j/trunk/src/main/java/org/jboss/logging/log4j/Log4jMDCProvider.java
===================================================================
--- common-logging-log4j/trunk/src/main/java/org/jboss/logging/log4j/Log4jMDCProvider.java	                        (rev 0)
+++ common-logging-log4j/trunk/src/main/java/org/jboss/logging/log4j/Log4jMDCProvider.java	2007-07-09 21:30:31 UTC (rev 2438)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.logging.log4j;
+
+import java.util.Map;
+
+import org.apache.log4j.MDC;
+import org.jboss.logging.MDCProvider;
+
+/**
+ * Log4j implementation of MDCProvider.
+ *
+ * @author Jason T. Greene
+ */
+public class Log4jMDCProvider implements MDCProvider
+{
+   public Object get(String key)
+   {
+      return MDC.get(key);
+   }
+
+   @SuppressWarnings("unchecked")
+   public Map<String, Object> getMap()
+   {
+      return MDC.getContext();
+   }
+
+   public void put(String key, Object val)
+   {
+      MDC.put(key, val);
+   }
+
+   public void remove(String key)
+   {
+      MDC.remove(key);
+   }
+}
\ No newline at end of file


Property changes on: common-logging-log4j/trunk/src/main/java/org/jboss/logging/log4j/Log4jMDCProvider.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF

Added: common-logging-log4j/trunk/src/main/java/org/jboss/logging/log4j/Log4jNDCProvider.java
===================================================================
--- common-logging-log4j/trunk/src/main/java/org/jboss/logging/log4j/Log4jNDCProvider.java	                        (rev 0)
+++ common-logging-log4j/trunk/src/main/java/org/jboss/logging/log4j/Log4jNDCProvider.java	2007-07-09 21:30:31 UTC (rev 2438)
@@ -0,0 +1,70 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.logging.log4j;
+
+import java.util.Stack;
+
+import org.apache.log4j.NDC;
+import org.jboss.logging.NDCProvider;
+
+/**
+ * Log4j implementation of NDCProvider, delegates to log4j NDC.
+ *
+ * @author Jason T. Greene
+ */
+public class Log4jNDCProvider implements NDCProvider
+{
+   public void clear()
+   {
+      NDC.clear();
+   }
+
+   public String get()
+   {
+      return NDC.get();
+   }
+
+   public int getDepth()
+   {
+      return NDC.getDepth();
+   }
+
+   public String peek()
+   {
+      return NDC.peek();
+   }
+
+   public String pop()
+   {
+      return NDC.pop();
+   }
+
+   public void push(String message)
+   {
+      NDC.push(message);
+   }
+
+   public void setMaxDepth(int maxDepth)
+   {
+      NDC.setMaxDepth(maxDepth);
+   }
+}
\ No newline at end of file


Property changes on: common-logging-log4j/trunk/src/main/java/org/jboss/logging/log4j/Log4jNDCProvider.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF




More information about the jboss-svn-commits mailing list