Skip to content

Commit

Permalink
- realigning with MDC as defined in SLF4J
Browse files Browse the repository at this point in the history
  • Loading branch information
ceki committed Jul 9, 2007
1 parent b264acd commit 1d03650
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 19 deletions.
@@ -0,0 +1,10 @@
package ch.qos.logback.classic.net;

class SocketAcceptor extends Thread {


@Override
public void run() {

}
}
Expand Up @@ -16,12 +16,13 @@
import java.io.Serializable;
import java.util.Map;

import org.slf4j.MDC;
import org.slf4j.Marker;
import org.slf4j.helpers.MessageFormatter;
import org.slf4j.impl.LogbackMDCAdapter;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.MDC;

/**
* The internal representation of logging events. When an affirmative decision
Expand Down Expand Up @@ -117,7 +118,9 @@ public LoggingEvent(String fqcn, Logger logger, Level level, String message,
}
timeStamp = System.currentTimeMillis();

mdcPropertyMap = MDC.getPropertyMap();
// the case is ugly but under the circumstances acceptable
LogbackMDCAdapter logbackMDCAdapter = (LogbackMDCAdapter) MDC.getMDCAdapter();
mdcPropertyMap = logbackMDCAdapter.getPropertyMap();
}

public void setArgumentArray(Object[] argArray) {
Expand Down
@@ -1,10 +1,10 @@
package ch.qos.logback.classic.turbo;

import org.slf4j.MDC;
import org.slf4j.Marker;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.MDC;
import ch.qos.logback.core.spi.FilterReply;

/**
Expand Down
@@ -1,9 +1,11 @@
package ch.qos.logback.classic;
package org.slf4j.impl;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.slf4j.spi.MDCAdapter;

/**
* A <em>Mapped Diagnostic Context</em>, or MDC in short, is an instrument for
* distinguishing interleaved log output from different sources. Log output is
Expand All @@ -15,15 +17,16 @@
* its parent.
* <p>
*
* For more information about turbo filters, please refer to the online manual at
* For more information about MDC, please refer to the online manual at
* http://logback.qos.ch/manual/mdc.html
*
* @author Ceki G&uuml;lc&uuml;
*/
public class MDC {
private static final ThreadLocal<HashMap<String, String>> threadLocal = new ThreadLocal<HashMap<String, String>>();
public class LogbackMDCAdapter implements MDCAdapter{

private final ThreadLocal<HashMap<String, String>> threadLocal = new ThreadLocal<HashMap<String, String>>();

private MDC() {
LogbackMDCAdapter() {
}

/**
Expand All @@ -40,7 +43,7 @@ private MDC() {
* and not send a reference to the old map, thus not allowing the remote logback
* component to see the latest changes.
*/
public static void put(String key, String val) {
public void put(String key, String val) {
HashMap<String, String> oldMap = threadLocal.get();

HashMap<String, String> newMap = new HashMap<String, String>();
Expand All @@ -58,7 +61,7 @@ public static void put(String key, String val) {
* <p>
* This method has no side effects.
*/
public static String get(String key) {
public String get(String key) {
HashMap<String, String> hashMap = threadLocal.get();

if ((hashMap != null) && (key != null)) {
Expand All @@ -77,7 +80,7 @@ public static String get(String key) {
* and not send a reference to the old map, thus not allowing the remote logback
* component to see the latest changes.
*/
public static void remove(String key) {
public void remove(String key) {
HashMap<String, String> oldMap = threadLocal.get();

HashMap<String, String> newMap = new HashMap<String, String>();
Expand All @@ -92,7 +95,7 @@ public static void remove(String key) {
/**
* Clear all entries in the MDC.
*/
public static void clear() {
public void clear() {
HashMap<String, String> hashMap = threadLocal.get();

if (hashMap != null) {
Expand All @@ -105,15 +108,15 @@ public static void clear() {
* Get the current thread's MDC as a map. This method is intended to be used
* internally.
*/
public static Map<String, String> getPropertyMap() {
public Map<String, String> getPropertyMap() {
return threadLocal.get();
}

/**
* Returns the keys in the MDC as a {@link Set}. The returned value
* can be null.
*/
public static Set<String> getKeys() {
public Set<String> getKeys() {
HashMap<String, String> hashMap = threadLocal.get();

if (hashMap != null) {
Expand Down
33 changes: 33 additions & 0 deletions logback-classic/src/main/java/org/slf4j/impl/StaticMDCBinder.java
@@ -0,0 +1,33 @@
package org.slf4j.impl;

import org.slf4j.spi.MDCAdapter;


/**
* This implementation is bound to {@link LogbackMDCAdapter}.
*
* @author Ceki G&uuml;lc&uuml;
*/
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 LogbackMDCAdapter();
}

public String getMDCAdapterClassStr() {
return LogbackMDCAdapter.class.getName();
}
}
@@ -1,5 +1,7 @@
package ch.qos.logback.classic;

import org.slf4j.MDC;

public class MDCTestThread extends Thread {

String val;
Expand Down
Expand Up @@ -7,10 +7,12 @@
import java.util.Map;

import junit.framework.TestCase;

import org.slf4j.MDC;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.MDC;
import ch.qos.logback.classic.spi.LoggerContextRemoteView;
import ch.qos.logback.classic.spi.LoggerRemoteView;
import ch.qos.logback.classic.spi.LoggingEvent;
Expand Down
Expand Up @@ -13,13 +13,13 @@

import junit.framework.TestCase;

import org.slf4j.MDC;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.MDC;
import ch.qos.logback.classic.net.mock.MockSocketServer;
import ch.qos.logback.classic.spi.LoggerContextRemoteView;
import ch.qos.logback.classic.spi.LoggerRemoteView;
Expand Down
Expand Up @@ -14,12 +14,12 @@

import junit.framework.TestCase;

import org.slf4j.MDC;
import org.slf4j.MarkerFactory;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.MDC;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.CoreGlobal;
import ch.qos.logback.core.net.SyslogConstants;
Expand Down
@@ -1,9 +1,11 @@
package ch.qos.logback.classic.pattern;

import junit.framework.TestCase;

import org.slf4j.MDC;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.MDC;
import ch.qos.logback.classic.spi.LoggingEvent;

public class MDCConverterTest extends TestCase {
Expand Down
Expand Up @@ -3,12 +3,12 @@
import java.util.ArrayList;
import java.util.List;

import org.slf4j.MDC;
import org.slf4j.Marker;

import ch.qos.logback.classic.ClassicGlobal;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.MDC;
import ch.qos.logback.core.spi.FilterReply;

/**
Expand Down

0 comments on commit 1d03650

Please sign in to comment.