[jboss-svn-commits] JBoss Common SVN: r3399 - 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
Wed Jul 29 17:17:12 EDT 2009


Author: david.lloyd at jboss.com
Date: 2009-07-29 17:17:12 -0400 (Wed, 29 Jul 2009)
New Revision: 3399

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/Log4jLoggerPluginInstance.java
Log:
Refactor to reuse logger instances always and complete i18n support for those logger backends which support it

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	2009-07-29 21:17:04 UTC (rev 3398)
+++ common-logging-log4j/trunk/src/main/java/org/jboss/logging/log4j/Log4jLoggerPlugin.java	2009-07-29 21:17:12 UTC (rev 3399)
@@ -26,11 +26,13 @@
 import org.jboss.logging.LoggerPluginInstance;
 import org.jboss.logging.MDCProvider;
 import org.jboss.logging.NDCProvider;
+import org.jboss.logging.NDCSupport;
+import org.jboss.logging.MDCSupport;
 
 /**
  *
  */
-public class Log4jLoggerPlugin implements LoggerPlugin {
+public class Log4jLoggerPlugin implements LoggerPlugin, NDCSupport, MDCSupport {
    private final MDCProvider mdcProvider;
    private final NDCProvider ndcProvider;
 
@@ -39,9 +41,8 @@
       ndcProvider = new Log4jNDCProvider();
    }
 
-   public LoggerPluginInstance getInstance(String name) {
-      Log4jLoggerPluginInstance instance = new Log4jLoggerPluginInstance();
-      instance.init(name);
+   public LoggerPluginInstance getInstance(String name, String resourceBundleName) {
+      Log4jLoggerPluginInstance instance = new Log4jLoggerPluginInstance(name, resourceBundleName);
       return instance;
    }
 

Modified: common-logging-log4j/trunk/src/main/java/org/jboss/logging/log4j/Log4jLoggerPluginInstance.java
===================================================================
--- common-logging-log4j/trunk/src/main/java/org/jboss/logging/log4j/Log4jLoggerPluginInstance.java	2009-07-29 21:17:04 UTC (rev 3398)
+++ common-logging-log4j/trunk/src/main/java/org/jboss/logging/log4j/Log4jLoggerPluginInstance.java	2009-07-29 21:17:12 UTC (rev 3399)
@@ -1,8 +1,8 @@
 /*
- * 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.
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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
@@ -23,12 +23,14 @@
 
 import org.jboss.logging.AbstractLoggerPluginInstance;
 import org.jboss.logging.LoggerPluginInstance;
+import org.jboss.logging.Logger;
 
 import org.apache.log4j.Category;
 import org.apache.log4j.Level;
 import org.apache.log4j.LogManager;
 
-import java.text.MessageFormat;
+import java.util.Map;
+import java.util.EnumMap;
 
 /**
  * Delegate for org.jboss.logging.Logger logging to log4j. Body of implementation
@@ -46,25 +48,18 @@
 
    // Constants -----------------------------------------------------
 
-   /**
-    *  Fully qualified classname for this class so Log4J locationinfo will be
-    *  correct
-    */
-   private static final String FQCN = Log4jLoggerPluginInstance.class.getName();
-
    // Attributes ----------------------------------------------------
 
    /** The Log4j delegate logger. */
-   private transient org.apache.log4j.Logger log;
+   private org.apache.log4j.Logger log;
 
    // Static --------------------------------------------------------
 
    // Constructors --------------------------------------------------
 
-   public Log4jLoggerPluginInstance() { }
-
-   public void init (String name)
+   public Log4jLoggerPluginInstance(final String name, final String resourceBundleName)
    {
+      super(name, resourceBundleName);
       log = LogManager.getLogger(name);
    }
 
@@ -80,68 +75,32 @@
     * 
     * @return the underlying logger
     */
-   public org.apache.log4j.Logger getLogger()
+   public org.apache.log4j.Logger getDelegateLogger()
    {
       return log;
    }
 
    // LoggerPlugin implementation ----------------------------------------------
 
-   public boolean isTraceEnabled()
-   {
-      Level l = Level.TRACE;
-      return log.isEnabledFor(l) && l.isGreaterOrEqual(log.getEffectiveLevel());
-   }
+   private static final Map<Logger.Level, Level> LEVELS;
 
-   public void trace(String loggerFcqn, Object message, Object[] params, Throwable t) {
-      if (isTraceEnabled()) {
-         final String str = String.valueOf(message);
-         log.log(FQCN, Level.TRACE, params == null ? str : MessageFormat.format(str, params), t);
-      }
+   static {
+      final EnumMap<Logger.Level, Level> map = new EnumMap<Logger.Level, Level>(Logger.Level.class);
+      map.put(Logger.Level.TRACE, Level.TRACE);
+      map.put(Logger.Level.DEBUG, Level.DEBUG);
+      map.put(Logger.Level.INFO, Level.INFO);
+      map.put(Logger.Level.WARN, Level.WARN);
+      map.put(Logger.Level.ERROR, Level.ERROR);
+      map.put(Logger.Level.FATAL, Level.FATAL);
+      LEVELS = map;
    }
 
-   @Deprecated
-   public boolean isDebugEnabled()
-   {
-      Level l = Level.DEBUG;
+   public boolean isEnabled(final Logger.Level level) {
+      final Level l = LEVELS.get(level);
       return log.isEnabledFor(l) && l.isGreaterOrEqual(log.getEffectiveLevel());
    }
 
-   @SuppressWarnings({"deprecation"})
-   public void debug(String loggerFcqn, Object message, Object[] params, Throwable t) {
-      if (isDebugEnabled()) {
-         final String str = String.valueOf(message);
-         log.log(FQCN, Level.DEBUG, params == null ? str : MessageFormat.format(str, params), t);
-      }
+   protected void log(final Logger.Level level, final String loggerFqcn, final String message, final Throwable t) {
+      log.log(loggerFqcn, LEVELS.get(level), message, t);
    }
-
-   @Deprecated
-   public boolean isInfoEnabled()
-   {
-      Level l = Level.INFO;
-      return log.isEnabledFor(l) && l.isGreaterOrEqual(log.getEffectiveLevel());
-   }
-
-   @SuppressWarnings({"deprecation"})
-   public void info(String loggerFcqn, Object message, Object[] params, Throwable t) {
-      if (isInfoEnabled()) {
-         final String str = String.valueOf(message);
-         log.log(FQCN, Level.INFO, params == null ? str : MessageFormat.format(str, params), t);
-      }
-   }
-
-   public void warn(String loggerFcqn, Object message, Object[] params, Throwable t) {
-      final String str = String.valueOf(message);
-      log.log(FQCN, Level.WARN, params == null ? str : MessageFormat.format(str, params), t);
-   }
-
-   public void error(String loggerFcqn, Object message, Object[] params, Throwable t) {
-      final String str = String.valueOf(message);
-      log.log(FQCN, Level.ERROR, params == null ? str : MessageFormat.format(str, params), t);
-   }
-
-   public void fatal(String loggerFcqn, Object message, Object[] params, Throwable t) {
-      final String str = String.valueOf(message);
-      log.log(FQCN, Level.FATAL, params == null ? str : MessageFormat.format(str, params), t);
-   }
 }



More information about the jboss-svn-commits mailing list