Skip to content
Browse files

import first version of the slf4j-jboss-logging adapter

  • Loading branch information...
1 parent 58356e7 commit bb89c3ad0b1d30c3de0b5b1c7b5f60edd4721169 Dimitris Andreadis committed May 13, 2008
View
7 .classpath
@@ -0,0 +1,7 @@
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="output" path="target/classes"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="var" path="M2_REPO/org/jboss/logging/jboss-logging-spi/2.0.5.GA/jboss-logging-spi-2.0.5.GA.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.4.3/slf4j-api-1.4.3.jar"/>
+</classpath>
View
13 .project
@@ -0,0 +1,13 @@
+<projectDescription>
+ <name>slf4j-jboss-logging</name>
+ <comment>slf4j to JBoss Logging Adapter</comment>
+ <projects/>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
5 .settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,5 @@
+#Mon Mar 31 14:11:36 CEST 2008
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
View
72 pom.xml
@@ -0,0 +1,72 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-parent</artifactId>
+ <version>3</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.slf4j</groupId>
+ <artifactId>slf4j-jboss-logging</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>slf4j to JBoss Logging Adapter</name>
+ <url>http://www.jboss.org</url>
+ <description>slf4j to JBoss Logging Adapter</description>
+ <scm>
+ <connection>scm:svn:https://svn.jboss.org/repos/common/slf4j-jboss-logging/trunk/</connection>
+ </scm>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-release-plugin</artifactId>
+ <configuration>
+ <!-- The tagBase property is needed during the release process so that the maven release plugin
+ will create the release tag in the appropriate location. -->
+ <tagBase>https://svn.jboss.org/repos/common/slf4j-jboss-logging/tags</tagBase>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>jboss.maven-plugins</groupId>
+ <artifactId>jboss-deploy-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
+ <repositories>
+ <repository>
+ <id>repository.jboss.org</id>
+ <name>JBoss Repository</name>
+ <layout>default</layout>
+ <url>http://repository.jboss.org/maven2/</url>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>snapshots.jboss.org</id>
+ <name>JBoss Snapshot Repository</name>
+ <layout>default</layout>
+ <url>http://snapshots.jboss.org/maven2/</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.4.3</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ <version>2.0.5.GA</version>
+ </dependency>
+ </dependencies>
+
+</project>
View
6 projectSet.psf
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<psf version="2.0">
+ <provider id="org.tigris.subversion.subclipse.core.svnnature">
+ <project reference="0.9.3,https://svn.jboss.org/repos/common/slf4j-jboss-logging/trunk,slf4j-jboss-logging"/>
+ </provider>
+</psf>
View
10 src/etc/default.mf
@@ -0,0 +1,10 @@
+Manifest-Version: 1.0
+Created-By: @java.vm.version@ (@java.vm.vendor@)
+Specification-Title: @specification.title@
+Specification-Version: @specification.version@
+Specification-Vendor: @specification.vendor@
+Implementation-Title: @implementation.title@
+Implementation-URL: @implementation.url@
+Implementation-Version: @implementation.version@
+Implementation-Vendor: @implementation.vendor@
+Implementation-Vendor-Id: @implementation.vendor.id@
View
278 src/main/java/org/jboss/slf4j/JBossLoggerAdapter.java
@@ -0,0 +1,278 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.slf4j;
+
+import org.slf4j.Logger;
+import org.slf4j.Marker;
+import org.slf4j.helpers.MarkerIgnoringBase;
+import org.slf4j.helpers.MessageFormatter;
+import org.slf4j.spi.LocationAwareLogger;
+
+/**
+ * A wrapper over {@link org.jboss.logging.Logger org.jboss.logging.Logger}
+ * in conformance with the {@link Logger} interface.
+ *
+ * Adapted from the corresponding slf4j-log4j adapter.
+ *
+ * @author <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
+ * @version <tt>$Revision: 2784 $</tt>
+ */
+public final class JBossLoggerAdapter extends MarkerIgnoringBase
+ implements LocationAwareLogger
+{
+ final org.jboss.logging.Logger logger;
+
+ // package access so that only JBossLoggerFactory be able to create one.
+ JBossLoggerAdapter(org.jboss.logging.Logger logger)
+ {
+ this.logger = logger;
+ }
+
+ public String getName()
+ {
+ return logger.getName();
+ }
+
+ public boolean isTraceEnabled()
+ {
+ return logger.isTraceEnabled();
+ }
+
+ public void trace(String msg)
+ {
+ logger.trace(msg);
+ }
+
+ public void trace(String format, Object arg)
+ {
+ if (logger.isTraceEnabled())
+ {
+ String msgStr = MessageFormatter.format(format, arg);
+ logger.trace(msgStr);
+ }
+ }
+
+ public void trace(String format, Object arg1, Object arg2)
+ {
+ if (logger.isTraceEnabled())
+ {
+ String msgStr = MessageFormatter.format(format, arg1, arg2);
+ logger.trace(msgStr);
+ }
+ }
+
+ public void trace(String format, Object[] argArray)
+ {
+ if (logger.isTraceEnabled())
+ {
+ String msgStr = MessageFormatter.arrayFormat(format, argArray);
+ logger.trace(msgStr);
+ }
+ }
+
+ public void trace(String msg, Throwable t)
+ {
+ logger.trace(msg, t);
+ }
+
+ public boolean isDebugEnabled()
+ {
+ return logger.isDebugEnabled();
+ }
+
+ public void debug(String msg)
+ {
+ logger.debug(msg);
+ }
+
+ public void debug(String format, Object arg)
+ {
+ if (logger.isDebugEnabled())
+ {
+ String msgStr = MessageFormatter.format(format, arg);
+ logger.debug(msgStr);
+ }
+ }
+
+ public void debug(String format, Object arg1, Object arg2)
+ {
+ if (logger.isDebugEnabled())
+ {
+ String msgStr = MessageFormatter.format(format, arg1, arg2);
+ logger.debug(msgStr);
+ }
+ }
+
+ public void debug(String format, Object[] argArray)
+ {
+ if (logger.isDebugEnabled())
+ {
+ String msgStr = MessageFormatter.arrayFormat(format, argArray);
+ logger.debug(msgStr);
+ }
+ }
+
+ public void debug(String msg, Throwable t)
+ {
+ logger.debug(msg, t);
+ }
+
+ public boolean isInfoEnabled()
+ {
+ return logger.isInfoEnabled();
+ }
+
+ public void info(String msg)
+ {
+ logger.info(msg);
+ }
+
+ public void info(String format, Object arg)
+ {
+ if (logger.isInfoEnabled())
+ {
+ String msgStr = MessageFormatter.format(format, arg);
+ logger.info(msgStr);
+ }
+ }
+
+ public void info(String format, Object arg1, Object arg2)
+ {
+ if (logger.isInfoEnabled())
+ {
+ String msgStr = MessageFormatter.format(format, arg1, arg2);
+ logger.info(msgStr);
+ }
+ }
+
+ public void info(String format, Object[] argArray)
+ {
+ if (logger.isInfoEnabled())
+ {
+ String msgStr = MessageFormatter.arrayFormat(format, argArray);
+ logger.info(msgStr);
+ }
+ }
+
+ public void info(String msg, Throwable t)
+ {
+ logger.info(msg, t);
+ }
+
+ public boolean isWarnEnabled()
+ {
+ // not supported by jboss-logging-spi
+ return true;
+ }
+
+ public void warn(String msg)
+ {
+ logger.warn(msg);
+ }
+
+ public void warn(String format, Object arg)
+ {
+ String msgStr = MessageFormatter.format(format, arg);
+ logger.warn(msgStr);
+ }
+
+ public void warn(String format, Object arg1, Object arg2)
+ {
+ String msgStr = MessageFormatter.format(format, arg1, arg2);
+ logger.warn(msgStr);
+ }
+
+ public void warn(String format, Object[] argArray)
+ {
+ String msgStr = MessageFormatter.arrayFormat(format, argArray);
+ logger.warn(msgStr);
+ }
+
+ public void warn(String msg, Throwable t)
+ {
+ logger.warn(msg, t);
+ }
+
+ public boolean isErrorEnabled()
+ {
+ // not supported by jboss-logging-spi
+ return true;
+ }
+
+ public void error(String msg)
+ {
+ logger.error(msg);
+ }
+
+ public void error(String format, Object arg)
+ {
+ String msgStr = MessageFormatter.format(format, arg);
+ logger.error(msgStr);
+ }
+
+ public void error(String format, Object arg1, Object arg2)
+ {
+ String msgStr = MessageFormatter.format(format, arg1, arg2);
+ logger.error(msgStr);
+ }
+
+ public void error(String format, Object[] argArray)
+ {
+ String msgStr = MessageFormatter.arrayFormat(format, argArray);
+ logger.error(msgStr);
+ }
+
+ public void error(String msg, Throwable t)
+ {
+ logger.error(msg, t);
+ }
+
+ public void log(Marker marker, String callerFQCN, int level, String msg, Throwable t)
+ {
+ // TODO - marker and callerFQCN not supported by jboss-logging-spi
+ switch(level)
+ {
+ case LocationAwareLogger.TRACE_INT:
+ logger.trace(msg, t);
+ break;
+
+ case LocationAwareLogger.DEBUG_INT:
+ logger.debug(msg, t);
+ break;
+
+ case LocationAwareLogger.INFO_INT:
+ logger.info(msg, t);
+ break;
+
+ case LocationAwareLogger.WARN_INT:
+ logger.warn(msg, t);
+ break;
+
+ case LocationAwareLogger.ERROR_INT:
+ logger.error(msg, t);
+ break;
+
+ default:
+ throw new IllegalStateException("Level number " + level + " is not recognized.");
+ }
+ }
+}
View
77 src/main/java/org/jboss/slf4j/JBossLoggerFactory.java
@@ -0,0 +1,77 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.slf4j;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.slf4j.ILoggerFactory;
+import org.slf4j.Logger;
+
+/**
+ * JBossLoggerFactory is an implementation of {@link ILoggerFactory} returning
+ * the appropriate named {@link JBossLoggerAdapter} instance.
+ *
+ * Adapted from the corresponding slf4j-log4j adapter.
+ *
+ * @author <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
+ * @version <tt>$Revision: 2784 $</tt>
+ */
+public class JBossLoggerFactory implements ILoggerFactory
+{
+ /** JBossLoggerAdapter cache */
+ Map loggerMap;
+
+ public JBossLoggerFactory()
+ {
+ loggerMap = new HashMap();
+ }
+
+ /**
+ * @see org.slf4j.ILoggerFactory#getLogger(java.lang.String)
+ */
+ public Logger getLogger(String name)
+ {
+ Logger slf4jLogger = null;
+
+ // protect against concurrent access of loggerMap
+ synchronized (this)
+ {
+ slf4jLogger = (Logger) loggerMap.get(name);
+
+ // no logger found
+ if (slf4jLogger == null)
+ {
+ // create a new jboss logger
+ org.jboss.logging.Logger jbossLogger;
+ jbossLogger = org.jboss.logging.Logger.getLogger(name);
+
+ // wrap it with an adapter
+ slf4jLogger = new JBossLoggerAdapter(jbossLogger);
+
+ // put it in the map
+ loggerMap.put(name, slf4jLogger);
+ }
+ }
+ return slf4jLogger;
+ }
+}
View
61 src/main/java/org/jboss/slf4j/JBossMDCAdapter.java
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.slf4j;
+
+import java.util.Map;
+
+import org.jboss.logging.MDC;
+import org.slf4j.spi.MDCAdapter;
+
+/**
+ * Adapted from the corresponding slf4j-log4j adapter.
+ *
+ * @author <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
+ * @version <tt>$Revision: 2784 $</tt>
+ */
+public class JBossMDCAdapter implements MDCAdapter
+{
+
+ public void clear()
+ {
+ Map map = MDC.getMap();
+
+ if (map != null)
+ map.clear();
+ }
+
+ public String get(String key)
+ {
+ return (String) MDC.get(key);
+ }
+
+ public void put(String key, String val)
+ {
+ MDC.put(key, val);
+ }
+
+ public void remove(String key)
+ {
+ MDC.remove(key);
+ }
+
+}
View
56 src/main/java/org/slf4j/impl/StaticLoggerBinder.java
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.slf4j.impl;
+
+import org.jboss.slf4j.JBossLoggerFactory;
+import org.slf4j.ILoggerFactory;
+import org.slf4j.spi.LoggerFactoryBinder;
+
+/**
+ * This implementation is bound to {@link JBossLoggerFactory}.
+ *
+ * @author <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
+ * @version <tt>$Revision: 2784 $</tt>
+ */
+public class StaticLoggerBinder implements LoggerFactoryBinder
+{
+ public static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
+
+ private static final String loggerFactoryClassStr = JBossLoggerFactory.class.getName();
+
+ private final ILoggerFactory loggerFactory;
+
+ private StaticLoggerBinder()
+ {
+ loggerFactory = new JBossLoggerFactory();
+ }
+
+ public ILoggerFactory getLoggerFactory()
+ {
+ return loggerFactory;
+ }
+
+ public String getLoggerFactoryClassStr()
+ {
+ return loggerFactoryClassStr;
+ }
+}
View
51 src/main/java/org/slf4j/impl/StaticMDCBinder.java
@@ -0,0 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.slf4j.impl;
+
+import org.jboss.slf4j.JBossMDCAdapter;
+import org.slf4j.spi.MDCAdapter;
+
+/**
+ * This implementation is bound to {@link JBossMDCAdapter}.
+ *
+ * @author <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
+ * @version <tt>$Revision: 2784 $</tt>
+ */
+public class StaticMDCBinder
+{
+ public static final StaticMDCBinder SINGLETON = new StaticMDCBinder();
+
+ private StaticMDCBinder()
+ {
+ // empty
+ }
+
+ public MDCAdapter getMDCA()
+ {
+ return new JBossMDCAdapter();
+ }
+
+ public String getMDCAdapterClassStr()
+ {
+ return JBossMDCAdapter.class.getName();
+ }
+}
View
56 src/main/java/org/slf4j/impl/StaticMarkerBinder.java
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, 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.slf4j.impl;
+
+import org.slf4j.IMarkerFactory;
+import org.slf4j.helpers.BasicMarkerFactory;
+import org.slf4j.spi.MarkerFactoryBinder;
+
+/**
+ * This implementation is bound to {@link BasicMarkerFactory}.
+ *
+ * @author <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
+ * @version <tt>$Revision: 2784 $</tt>
+ */
+public class StaticMarkerBinder implements MarkerFactoryBinder
+{
+
+ public static final StaticMarkerBinder SINGLETON = new StaticMarkerBinder();
+
+ final IMarkerFactory markerFactory = new BasicMarkerFactory();
+
+ private StaticMarkerBinder()
+ {
+ // empty
+ }
+
+ public IMarkerFactory getMarkerFactory()
+ {
+ return markerFactory;
+ }
+
+ public String getMarkerFactoryClassStr()
+ {
+ return BasicMarkerFactory.class.getName();
+ }
+
+}

0 comments on commit bb89c3a

Please sign in to comment.
Something went wrong with that request. Please try again.