You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4j-dev@logging.apache.org by rg...@apache.org on 2011/02/07 02:11:41 UTC

svn commit: r1067833 [2/2] - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers: ./ log4j2-api/src/main/java/org/apache/logging/log4j/ log4j2-api/src/main/java/org/apache/logging/log4j/spi/ log4j2-api/src/test/java/org/apache/logging/log4j/ log4...

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/helpers/Log4JMDCAdapter.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/helpers/Log4JMDCAdapter.java?rev=1067833&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/helpers/Log4JMDCAdapter.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/helpers/Log4JMDCAdapter.java Mon Feb  7 01:11:40 2011
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.slf4j.helpers;
+
+import org.apache.logging.log4j.ThreadContext;
+import org.slf4j.spi.MDCAdapter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ *
+ */
+public class Log4JMDCAdapter implements MDCAdapter {
+
+    public void put(String key, String val) {
+        ThreadContext.put(key, val);
+    }
+
+    public String get(String key) {
+        return ThreadContext.get(key).toString();
+    }
+
+    public void remove(String key) {
+        ThreadContext.remove(key);
+    }
+
+    public void clear() {
+        ThreadContext.clear();
+    }
+
+    public Map getCopyOfContextMap() {
+        Map<String, Object> ctx = ThreadContext.getContext();
+        Map<String, String> map = new HashMap<String, String>();
+
+        for (Map.Entry<String, Object>entry : ctx.entrySet()) {
+            map.put(entry.getKey(), entry.getValue().toString());
+        }
+        return map;
+    }
+
+    public void setContextMap(Map map) {
+        ThreadContext.clear();
+        for (Map.Entry<String, String> entry : ((Map<String, String>) map).entrySet()) {
+            ThreadContext.put(entry.getKey(), entry.getValue());
+        }
+    }
+}

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/helpers/Log4JMarkerFactory.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/helpers/Log4JMarkerFactory.java?rev=1067833&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/helpers/Log4JMarkerFactory.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/helpers/Log4JMarkerFactory.java Mon Feb  7 01:11:40 2011
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.slf4j.helpers;
+
+import org.slf4j.IMarkerFactory;
+import org.slf4j.Marker;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ *
+ */
+public class Log4JMarkerFactory implements IMarkerFactory {
+
+    private ConcurrentMap<String, Marker> markerMap = new ConcurrentHashMap<String, Marker>();
+
+    public Marker getMarker(String name) {
+        if (name == null) {
+            throw new IllegalArgumentException("Marker name must not be null");
+        }
+        Marker marker = markerMap.get(name);
+        if (marker == null) {
+            marker = new MarkerWrapper(name);
+        }
+        return marker;
+    }
+
+    public boolean exists(String name) {
+        return markerMap.containsKey(name);
+    }
+
+    public boolean detachMarker(String name) {
+        return false;
+    }
+
+    public Marker getDetachedMarker(String name) {
+        return new MarkerWrapper(name);
+    }
+}

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/helpers/MarkerWrapper.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/helpers/MarkerWrapper.java?rev=1067833&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/helpers/MarkerWrapper.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/helpers/MarkerWrapper.java Mon Feb  7 01:11:40 2011
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.slf4j.helpers;
+
+import org.apache.logging.log4j.Marker;
+
+/**
+ *
+ */
+public class MarkerWrapper extends BasicMarker implements Marker {
+    private static final long serialVersionUID = 1903952589649545191L;
+
+    private MarkerWrapper parent;
+
+    MarkerWrapper(String name) {
+        super(name);
+    }
+
+    @Override
+    public void add(org.slf4j.Marker reference) {
+        super.add(reference);
+        ((MarkerWrapper)reference).setParent(this);
+    }
+
+    private void setParent(MarkerWrapper marker) {
+        parent = marker;
+    }
+
+    public org.apache.logging.log4j.Marker getParent() {
+        return this.parent;
+    }
+
+    public boolean isInstanceOf(org.apache.logging.log4j.Marker marker) {
+        if (marker == null) {
+            throw new IllegalArgumentException("A marker parameter is required");
+        }
+
+        return contains((MarkerWrapper) marker);
+    }
+}

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/Log4JLogger.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/Log4JLogger.java?rev=1067833&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/Log4JLogger.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/Log4JLogger.java Mon Feb  7 01:11:40 2011
@@ -0,0 +1,252 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.slf4j.impl;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.Logger;
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.message.Message;
+import org.apache.logging.log4j.message.ParameterizedMessage;
+import org.apache.logging.log4j.message.StructuredDataMessage;
+import org.slf4j.Marker;
+import org.slf4j.MarkerFactory;
+import org.slf4j.ext.EventData;
+import org.slf4j.spi.LocationAwareLogger;
+
+import java.util.Map;
+
+/**
+ *
+ */
+public class Log4JLogger extends Logger implements LocationAwareLogger {
+
+    private static final String FQCN = Log4JLogger.class.getName();
+    private static Marker EVENT_MARKER = MarkerFactory.getMarker("EVENT");
+    private final boolean eventLogger;
+
+    public Log4JLogger(LoggerContext context, String name) {
+        super(context, name);
+        eventLogger = "EventLogger".equals(name);
+    }
+
+    public void log(Marker marker, String fqcn, int i, String s1, Object[] objects, Throwable throwable) {
+        Message msg;
+        if (eventLogger && marker != null && marker.contains(EVENT_MARKER)) {
+            try {
+                EventData data = (objects != null && objects[0] instanceof EventData) ? (EventData) objects[0] :
+                    new EventData(s1);
+                msg = new StructuredDataMessage(data.getEventId(), data.getMessage(), data.getEventType());
+                for (Map.Entry entry : data.getEventMap().entrySet()) {
+                    String key = entry.getKey().toString();
+                    if (EventData.EVENT_TYPE.equals(key) || EventData.EVENT_ID.equals(key) ||
+                        EventData.EVENT_MESSAGE.equals(key)) {
+                        continue;
+                    }
+                    ((StructuredDataMessage) msg).put(entry.getKey().toString(), entry.getValue().toString());
+                }
+            } catch (Exception ex) {
+                msg = new ParameterizedMessage(s1, objects, throwable);
+            }
+
+        } else {
+            msg = new ParameterizedMessage(s1, objects, throwable);
+        }
+        super.log((org.apache.logging.log4j.Marker) marker, fqcn, getLevel(i), msg, throwable);
+    }
+
+    public void trace(String format, Object o) {
+        super.trace(format, o);
+    }
+
+    public void trace(String format, Object arg1, Object arg2) {
+        super.trace(format, arg1, arg2);
+    }
+
+    public boolean isTraceEnabled(Marker marker) {
+        return super.isTraceEnabled((org.apache.logging.log4j.Marker) marker);
+    }
+
+    public void trace(Marker marker, String s) {
+        super.trace((org.apache.logging.log4j.Marker) marker, s);
+    }
+
+    public void trace(Marker marker, String s, Object o) {
+        super.trace((org.apache.logging.log4j.Marker) marker, s, o);
+    }
+
+    public void trace(Marker marker, String s, Object o, Object o1) {
+        super.trace((org.apache.logging.log4j.Marker) marker, s, o, o1);
+    }
+
+    public void trace(Marker marker, String s, Object[] objects) {
+        super.trace((org.apache.logging.log4j.Marker) marker, s , objects);
+    }
+
+    public void trace(Marker marker, String s, Throwable throwable) {
+        super.trace((org.apache.logging.log4j.Marker) marker, s, throwable);
+    }
+
+    public void debug(String format, Object o) {
+        super.debug(format, o);
+    }
+
+    public void debug(String format, Object o, Object o1) {
+        super.debug(format, o, o1);
+    }
+
+    public boolean isDebugEnabled(Marker marker) {
+        return super.isDebugEnabled((org.apache.logging.log4j.Marker) marker);
+    }
+
+    public void debug(Marker marker, String s) {
+        super.debug((org.apache.logging.log4j.Marker) marker, s);
+    }
+
+    public void debug(Marker marker, String s, Object o) {
+        super.debug((org.apache.logging.log4j.Marker) marker, s, o);
+    }
+
+    public void debug(Marker marker, String s, Object o, Object o1) {
+        super.debug((org.apache.logging.log4j.Marker) marker, s, o, o1);
+    }
+
+    public void debug(Marker marker, String s, Object[] objects) {
+        super.debug((org.apache.logging.log4j.Marker) marker, s, objects);
+    }
+
+    public void debug(Marker marker, String s, Throwable throwable) {
+        super.debug((org.apache.logging.log4j.Marker) marker, s, throwable);
+    }
+
+    public void info(String s, Object o) {
+        super.info(s, o);
+    }
+
+    public void info(String s, Object o, Object o1) {
+        super.info(s, o, o1);
+    }
+
+    public boolean isInfoEnabled(Marker marker) {
+        return super.isInfoEnabled((org.apache.logging.log4j.Marker) marker);
+    }
+
+    public void info(Marker marker, String s) {
+        super.info((org.apache.logging.log4j.Marker) marker, s);
+    }
+
+    public void info(Marker marker, String s, Object o) {
+        super.info((org.apache.logging.log4j.Marker) marker, s, o);
+    }
+
+    public void info(Marker marker, String s, Object o, Object o1) {
+        super.info((org.apache.logging.log4j.Marker) marker, s, o, o1);
+    }
+
+    public void info(Marker marker, String s, Object[] objects) {
+        super.info((org.apache.logging.log4j.Marker) marker, s, objects);
+    }
+
+    public void info(Marker marker, String s, Throwable throwable) {
+        super.info((org.apache.logging.log4j.Marker) marker, s, throwable);
+    }
+
+    public void warn(String s, Object o) {
+        super.warn(s, o);
+    }
+
+    public void warn(String s, Object o, Object o1) {
+        super.warn(s, o, o1);
+    }
+
+    public boolean isWarnEnabled(Marker marker) {
+        return super.isWarnEnabled((org.apache.logging.log4j.Marker) marker);
+    }
+
+    public void warn(Marker marker, String s) {
+        super.warn((org.apache.logging.log4j.Marker) marker, s);
+    }
+
+    public void warn(Marker marker, String s, Object o) {
+        super.warn((org.apache.logging.log4j.Marker) marker, s, o);
+    }
+
+    public void warn(Marker marker, String s, Object o, Object o1) {
+        super.warn((org.apache.logging.log4j.Marker) marker, s, o, o1);
+    }
+
+    public void warn(Marker marker, String s, Object[] objects) {
+        super.warn((org.apache.logging.log4j.Marker) marker, s, objects);
+    }
+
+    public void warn(Marker marker, String s, Throwable throwable) {
+        super.warn((org.apache.logging.log4j.Marker) marker, s, throwable);
+    }
+
+    public void error(String s, Object o) {
+        super.error(s, o);
+    }
+
+    public void error(String s, Object o, Object o1) {
+        super.error(s, o, o1);
+    }
+
+    public boolean isErrorEnabled(Marker marker) {
+        return super.isErrorEnabled((org.apache.logging.log4j.Marker) marker);
+    }
+
+    public void error(Marker marker, String s) {
+        super.error((org.apache.logging.log4j.Marker) marker, s);
+    }
+
+    public void error(Marker marker, String s, Object o) {
+        super.error((org.apache.logging.log4j.Marker) marker, s, o);
+    }
+
+    public void error(Marker marker, String s, Object o, Object o1) {
+        super.error((org.apache.logging.log4j.Marker) marker, s, o, o1);
+    }
+
+    public void error(Marker marker, String s, Object[] objects) {
+        super.error((org.apache.logging.log4j.Marker) marker, s, objects);
+    }
+
+    public void error(Marker marker, String s, Throwable throwable) {
+        super.error((org.apache.logging.log4j.Marker) marker, s, throwable);
+    }
+
+    @Override
+    protected String getFQCN() {
+        return FQCN;
+    }
+
+    private Level getLevel(int i) {
+
+        switch (i) {
+            case TRACE_INT :
+                return Level.TRACE;
+            case DEBUG_INT :
+                return Level.DEBUG;
+            case INFO_INT :
+                return Level.INFO;
+            case WARN_INT :
+                return Level.WARN;
+            case ERROR_INT :
+                return Level.ERROR;
+        }
+        return Level.ERROR;
+    }
+}

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/StaticLoggerBinder.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/StaticLoggerBinder.java?rev=1067833&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/StaticLoggerBinder.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/StaticLoggerBinder.java Mon Feb  7 01:11:40 2011
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.slf4j.impl;
+
+import org.slf4j.ILoggerFactory;
+import org.slf4j.helpers.Log4JLoggerFactory;
+import org.slf4j.spi.LoggerFactoryBinder;
+
+/**
+ *
+ */
+public class StaticLoggerBinder implements LoggerFactoryBinder {
+
+    /**
+     * The unique instance of this class.
+     */
+    private static final StaticLoggerBinder SINGLETON = new StaticLoggerBinder();
+
+    /**
+     * Return the singleton of this class.
+     *
+     * @return the StaticLoggerBinder singleton
+     */
+    public static final StaticLoggerBinder getSingleton() {
+        return SINGLETON;
+    }
+
+    /**
+     * Declare the version of the SLF4J API this implementation is compiled
+     * against. The value of this field is usually modified with each release.
+     */
+    // to avoid constant folding by the compiler, this field must *not* be final
+    public static String REQUESTED_API_VERSION = "1.6"; // !final
+
+    private static final String loggerFactoryClassStr = Log4JLoggerFactory.class.getName();
+    /**
+     * The ILoggerFactory instance returned by the {@link #getLoggerFactory}
+     * method should always be the same object
+     */
+    private final ILoggerFactory loggerFactory;
+
+    private StaticLoggerBinder() {
+        loggerFactory = new Log4JLoggerFactory();
+    }
+
+    public ILoggerFactory getLoggerFactory() {
+        return loggerFactory;
+    }
+
+    public String getLoggerFactoryClassStr() {
+        return loggerFactoryClassStr;
+    }
+}

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/StaticMDCBinder.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/StaticMDCBinder.java?rev=1067833&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/StaticMDCBinder.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/StaticMDCBinder.java Mon Feb  7 01:11:40 2011
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.slf4j.impl;
+
+import org.slf4j.helpers.Log4JMDCAdapter;
+import org.slf4j.spi.MDCAdapter;
+
+/**
+ *
+ */
+public class StaticMDCBinder {
+
+    /**
+     * The unique instance of this class.
+     */
+    public static final StaticMDCBinder SINGLETON = new StaticMDCBinder();
+
+    private StaticMDCBinder() {
+    }
+
+    /**
+     * Currently this method always returns an instance of {@link StaticMDCBinder}.
+     */
+    public MDCAdapter getMDCA() {
+        return new Log4JMDCAdapter();
+    }
+
+    public String getMDCAdapterClassStr() {
+        return Log4JMDCAdapter.class.getName();
+    }
+}

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/StaticMarkerBinder.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/StaticMarkerBinder.java?rev=1067833&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/StaticMarkerBinder.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/main/java/org/slf4j/impl/StaticMarkerBinder.java Mon Feb  7 01:11:40 2011
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.slf4j.impl;
+
+import org.slf4j.IMarkerFactory;
+import org.slf4j.helpers.Log4JMarkerFactory;
+import org.slf4j.spi.MarkerFactoryBinder;
+
+/**
+ *
+ */
+public class StaticMarkerBinder implements MarkerFactoryBinder
+{
+
+    /**
+     * The unique instance of this class.
+     */
+    public static final StaticMarkerBinder SINGLETON = new StaticMarkerBinder();
+
+    final IMarkerFactory markerFactory = new Log4JMarkerFactory();
+
+    public IMarkerFactory getMarkerFactory()
+    {
+        return markerFactory;
+    }
+
+    public String getMarkerFactoryClassStr()
+    {
+        return Log4JMarkerFactory.class.getName();
+    }
+}

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java?rev=1067833&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/test/java/org/apache/logging/slf4j/LoggerTest.java Mon Feb  7 01:11:40 2011
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.slf4j;
+
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.XMLConfigurationFactory;
+import org.apache.logging.log4j.internal.StatusLogger;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+import org.slf4j.ext.EventData;
+import org.slf4j.ext.EventLogger;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+import org.slf4j.helpers.Log4JLoggerFactory;
+
+import java.util.Locale;
+
+
+/**
+ *
+ */
+public class LoggerTest {
+
+    private static final String CONFIG = "log4j-test1.xml";
+
+    @BeforeClass
+    public static void setupClass() {
+        System.setProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY, CONFIG);
+        LoggerContext ctx = Log4JLoggerFactory.getContext();
+        Configuration config = ctx.getConfiguration();
+    }
+
+    @AfterClass
+    public static void cleanupClass() {
+        System.clearProperty(XMLConfigurationFactory.CONFIGURATION_FILE_PROPERTY);
+        LoggerContext ctx = Log4JLoggerFactory.getContext();
+        ctx.reconfigure();
+        StatusLogger.getLogger().reset();
+    }
+
+    Logger logger = LoggerFactory.getLogger("LoggerTest");
+    XLogger xlogger = XLoggerFactory.getXLogger("LoggerTest");
+
+    @Test
+    public void basicFlow() {
+        xlogger.entry();
+        xlogger.exit();
+    }
+
+    @Test
+    public void simpleFlow() {
+        xlogger.entry(CONFIG);
+        xlogger.exit(0);
+    }
+
+    @Test
+    public void throwing() {
+        xlogger.throwing(new IllegalArgumentException("Test Exception"));
+    }
+
+    @Test
+    public void catching() {
+        try {
+            throw new NullPointerException();
+        } catch (Exception e) {
+            xlogger.catching(e);
+        }
+    }
+
+    @Test
+    public void debug() {
+        logger.debug("Debug message");
+    }
+
+
+    @Test
+    public void debugWithParms() {
+        logger.debug("Hello, {}", "World");
+    }
+
+    @Test
+    public void mdc() {
+
+        MDC.put("TestYear", "2010");
+        logger.debug("Debug message");
+        MDC.clear();
+        logger.debug("Debug message");
+    }
+
+    @Test
+    public void testEventLogger() {
+        MDC.put("loginId", "JohnDoe");
+        MDC.put("ipAddress", "192.168.0.120");
+        MDC.put("locale", Locale.US.getDisplayName());
+        EventData data = new EventData();
+        data.setEventType("Transfer");
+        data.setEventId("Audit@18060");
+        data.setMessage("Transfer Complete");
+        data.put("ToAccount", "123456");
+        data.put("FromAccount", "123457");
+        data.put("Amount", "200.00");
+        EventLogger.logEvent(data);
+        MDC.clear();
+    }
+}

Added: logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/test/resources/log4j-test1.xml
URL: http://svn.apache.org/viewvc/logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/test/resources/log4j-test1.xml?rev=1067833&view=auto
==============================================================================
--- logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/test/resources/log4j-test1.xml (added)
+++ logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers/slf4j-impl/src/test/resources/log4j-test1.xml Mon Feb  7 01:11:40 2011
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<configuration packages="" status="debug" name="LoggerTest">
+  <properties>
+    <property name="filename">target/test.log</property>
+  </properties>
+  <filters>
+    <Threshold level="trace"/>
+  </filters>
+
+  <appenders>
+    <Console name="EventLogger">
+      <PatternLayout pattern="%m%n"/>
+    </Console>
+    <Console name="STDOUT">
+      <PatternLayout pattern="%m MDC%X%n"/>
+    </Console>
+    <File name="File" fileName="${filename}">
+      <PatternLayout>
+        <pattern>%d %p %C{1.} [%t] %m%n</pattern>
+      </PatternLayout>
+    </File>
+    <List name="List">
+      <filters>
+        <Threshold level="error"/>
+      </filters>
+    </List>
+  </appenders>
+
+  <loggers>
+    <logger name="EventLogger" level="info" additivity="false">
+      <appender-ref ref="EventLogger"/>
+    </logger>>
+
+    <logger name="org.apache.logging.log4j.test2" level="debug" additivity="false">
+      <appender-ref ref="File"/>
+    </logger>>
+
+    <root level="trace">
+      <appender-ref ref="STDOUT"/>
+    </root>
+  </loggers>
+
+</configuration>
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Re: svn commit: r1067833 [2/2] - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers: ./ log4j2-api/src/main/java/org/apache/logging/log4j/ log4j2-api/src/main/java/org/apache/logging/log4j/spi/ log4j2-api/src/test/java/org/apache/logging/log4j/ log4...

Posted by Ralph Goers <ra...@dslextreme.com>.
Sure. 

SLF4J requires that StaticLoggerBinder, StaticMarkerBinder and StaticMDCBinder be implemented with specific package and class names - it looks for them in the class path to determine the implementation of the API (Note that this is different than how I've implemented the Log4j 2 API - it binds by looking for a log4j-provider.xml and getting the class names from it).  In order for MarkerWrapper to extend BasicMarker it has to be in the same package since BasicMarker's constructor is package protected. Since MarkerWrapper's constructor is protected Log4JMarkerFactory needs to be in the same package.  Log4JLoggerFactory and Log4JMDCFactory could have been in any package but since they implement SLF4J interfaces keeping them together with the other classes just made sense to me. As for Log4JLogger, it too could be in any package but it is tied to both the SLF4J API and the Log4J2 API and keeping it in the org.slf4j package makes it clear it isn't directly part of the Log4J 2 implementation.

In short, to implement the SLF4J API using the org.slf4j namespace is unavoidable.

Ralph


On Feb 6, 2011, at 9:26 PM, Curt Arnold wrote:

> Could you provide some background on the use of the org.slf4j namespace in the commit?
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-dev-help@logging.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Re: svn commit: r1067833 [2/2] - in /logging/log4j/branches/BRANCH_2_0_EXPERIMENTAL/rgoers: ./ log4j2-api/src/main/java/org/apache/logging/log4j/ log4j2-api/src/main/java/org/apache/logging/log4j/spi/ log4j2-api/src/test/java/org/apache/logging/log4j/ log4...

Posted by Curt Arnold <ca...@apache.org>.
Could you provide some background on the use of the org.slf4j namespace in the commit?
---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org