[jboss-svn-commits] JBoss Common SVN: r4005 - jboss-logging/trunk/src/main/java/org/jboss/logging.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Feb 9 00:38:56 EST 2010
Author: david.lloyd at jboss.com
Date: 2010-02-09 00:38:55 -0500 (Tue, 09 Feb 2010)
New Revision: 4005
Added:
jboss-logging/trunk/src/main/java/org/jboss/logging/MDC.java
jboss-logging/trunk/src/main/java/org/jboss/logging/NDC.java
Modified:
jboss-logging/trunk/src/main/java/org/jboss/logging/JBossLogManagerLogger.java
jboss-logging/trunk/src/main/java/org/jboss/logging/JBossLogManagerProvider.java
jboss-logging/trunk/src/main/java/org/jboss/logging/JDKLevel.java
jboss-logging/trunk/src/main/java/org/jboss/logging/Logger.java
Log:
Add MDC, NDC; cache logger instances in logmanager impl; limit public API (for now)
Modified: jboss-logging/trunk/src/main/java/org/jboss/logging/JBossLogManagerLogger.java
===================================================================
--- jboss-logging/trunk/src/main/java/org/jboss/logging/JBossLogManagerLogger.java 2010-02-09 04:31:25 UTC (rev 4004)
+++ jboss-logging/trunk/src/main/java/org/jboss/logging/JBossLogManagerLogger.java 2010-02-09 05:38:55 UTC (rev 4005)
@@ -30,13 +30,9 @@
private final org.jboss.logmanager.Logger logger;
- JBossLogManagerLogger(final String name, final String resourceBundleName, final String prefix) {
+ JBossLogManagerLogger(final String name, final String resourceBundleName, final String prefix, final org.jboss.logmanager.Logger logger) {
super(name, resourceBundleName, prefix);
- if (resourceBundleName != null) {
- logger = org.jboss.logmanager.Logger.getLogger(name, resourceBundleName);
- } else {
- logger = org.jboss.logmanager.Logger.getLogger(name);
- }
+ this.logger = logger;
}
public boolean isEnabled(final Level level) {
Modified: jboss-logging/trunk/src/main/java/org/jboss/logging/JBossLogManagerProvider.java
===================================================================
--- jboss-logging/trunk/src/main/java/org/jboss/logging/JBossLogManagerProvider.java 2010-02-09 04:31:25 UTC (rev 4004)
+++ jboss-logging/trunk/src/main/java/org/jboss/logging/JBossLogManagerProvider.java 2010-02-09 05:38:55 UTC (rev 4005)
@@ -26,10 +26,36 @@
import org.jboss.logmanager.MDC;
import org.jboss.logmanager.NDC;
+import static org.jboss.logmanager.Logger.AttachmentKey;
+
final class JBossLogManagerProvider implements LoggerProvider {
+ private static final AttachmentKey<Logger> KEY = new AttachmentKey<Logger>();
+
public Logger getLogger(final String name, final String resourceBundleName, final String prefix) {
- return new JBossLogManagerLogger(name, resourceBundleName, prefix);
+ final org.jboss.logmanager.Logger logger;
+ if (resourceBundleName != null) {
+ logger = org.jboss.logmanager.Logger.getLogger(name, resourceBundleName);
+ } else {
+ logger = org.jboss.logmanager.Logger.getLogger(name);
+ }
+ Logger l = logger.getAttachment(KEY);
+ for (;;) {
+ if (l != null) {
+ if (l.getPrefix().equals(prefix)) {
+ return l;
+ }
+ return new JBossLogManagerLogger(name, resourceBundleName, prefix, logger);
+ } else {
+ l = new JBossLogManagerLogger(name, resourceBundleName, prefix, logger);
+ Logger a = logger.attachIfAbsent(KEY, l);
+ if (a == null) {
+ return l;
+ }
+ l = a;
+ // try again...
+ }
+ }
}
public void putMdc(final String key, final Object value) {
Modified: jboss-logging/trunk/src/main/java/org/jboss/logging/JDKLevel.java
===================================================================
--- jboss-logging/trunk/src/main/java/org/jboss/logging/JDKLevel.java 2010-02-09 04:31:25 UTC (rev 4004)
+++ jboss-logging/trunk/src/main/java/org/jboss/logging/JDKLevel.java 2010-02-09 05:38:55 UTC (rev 4005)
@@ -27,7 +27,7 @@
/**
* Levels used by the JDK logging back end.
*/
-public final class JDKLevel extends Level {
+final class JDKLevel extends Level {
private static final long serialVersionUID = 1L;
Modified: jboss-logging/trunk/src/main/java/org/jboss/logging/Logger.java
===================================================================
--- jboss-logging/trunk/src/main/java/org/jboss/logging/Logger.java 2010-02-09 04:31:25 UTC (rev 4004)
+++ jboss-logging/trunk/src/main/java/org/jboss/logging/Logger.java 2010-02-09 05:38:55 UTC (rev 4005)
@@ -71,6 +71,15 @@
}
/**
+ * Get the log message prefix string.
+ *
+ * @return the log message prefix string
+ */
+ public String getPrefix() {
+ return prefix;
+ }
+
+ /**
* Check to see if the given level is enabled for this logger.
*
* @param level the level to check for
Added: jboss-logging/trunk/src/main/java/org/jboss/logging/MDC.java
===================================================================
--- jboss-logging/trunk/src/main/java/org/jboss/logging/MDC.java (rev 0)
+++ jboss-logging/trunk/src/main/java/org/jboss/logging/MDC.java 2010-02-09 05:38:55 UTC (rev 4005)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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
+ * 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;
+
+import java.util.Map;
+
+public final class MDC {
+
+ private MDC() {
+ }
+
+ public static void put(String key, Object val) {
+ LoggerProviders.PROVIDER.putMdc(key, val);
+ }
+
+ public static Object get(String key) {
+ return LoggerProviders.PROVIDER.getMdc(key);
+ }
+
+ public static void remove(String key) {
+ LoggerProviders.PROVIDER.removeMdc(key);
+ }
+
+ public static Map<String, Object> getMap() {
+ return LoggerProviders.PROVIDER.getMdcMap();
+ }
+}
Added: jboss-logging/trunk/src/main/java/org/jboss/logging/NDC.java
===================================================================
--- jboss-logging/trunk/src/main/java/org/jboss/logging/NDC.java (rev 0)
+++ jboss-logging/trunk/src/main/java/org/jboss/logging/NDC.java 2010-02-09 05:38:55 UTC (rev 4005)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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
+ * 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;
+
+public final class NDC {
+
+ private NDC() {
+ }
+
+ public static void clear() {
+ LoggerProviders.PROVIDER.clearNdc();
+ }
+
+ public static String get() {
+ return LoggerProviders.PROVIDER.getNdc();
+ }
+
+ public static int getDepth() {
+ return LoggerProviders.PROVIDER.getNdcDepth();
+ }
+
+ public static String pop() {
+ return LoggerProviders.PROVIDER.popNdc();
+ }
+
+ public static String peek() {
+ return LoggerProviders.PROVIDER.peekNdc();
+ }
+
+ public static void push(String message) {
+ LoggerProviders.PROVIDER.pushNdc(message);
+ }
+
+ public static void setMaxDepth(int maxDepth) {
+ LoggerProviders.PROVIDER.setNdcMaxDepth(maxDepth);
+ }
+}
More information about the jboss-svn-commits
mailing list