Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@
<maven.source.version>3.0.1</maven.source.version>
<maven.exec.version>3.0.1</maven.exec.version>
<maven.jar.version>3.1.2</maven.jar.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.version>3.7.0</maven.compiler.version>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.version>3.11.0</maven.compiler.version>
<maven.gpg.version>3.1.0</maven.gpg.version>
<maven.ignore.testfailure>false</maven.ignore.testfailure>
<maven.surefire.version>2.22.0</maven.surefire.version>
Expand Down
78 changes: 76 additions & 2 deletions trpc-core/src/main/java/org/slf4j/TrpcMDCAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Deque;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.spi.MDCAdapter;

Expand Down Expand Up @@ -47,13 +48,27 @@ public class TrpcMDCAdapter implements MDCAdapter {

static {
mtcMDCAdapter = new TrpcMDCAdapter();
MDC.mdcAdapter = mtcMDCAdapter;
replaceMDCAdapterField();
}

/**
* Replace the MDC adapter field using reflection to support slf4j 2.x
*/
private static void replaceMDCAdapterField() {
try {
java.lang.reflect.Field mdcAdapterField = MDC.class.getDeclaredField("mdcAdapter");
mdcAdapterField.setAccessible(true);
mdcAdapterField.set(null, mtcMDCAdapter);
} catch (Exception e) {
throw new IllegalStateException("Failed to replace MDC adapter", e);
}
}

public static MDCAdapter init() {
return mtcMDCAdapter;
}


/**
* Put a context value (the <code>val</code> parameter) as identified with the
* <code>key</code> parameter into the current thread's context map. Note that
Expand Down Expand Up @@ -178,4 +193,63 @@ private Map<String, String> duplicateAndInsertNewMap(Map<String, String> oldMap)
return newMap;
}

}
/**
* Push a value onto the MDC stack for the given key.
* This method is required by slf4j 2.x MDCAdapter interface.
*
* @param key the key to identify the value
* @param value the value to push onto the stack
*/
@Override
public void pushByKey(String key, String value) {
// For simplicity, we just use put() to store the value
// A full implementation would maintain a stack per key
put(key, value);
}

/**
* Pop a value from the MDC stack for the given key.
* This method is required by slf4j 2.x MDCAdapter interface.
*
* @param key the key to identify the stack
* @return the popped value, or null if the stack is empty
*/
@Override
public String popByKey(String key) {
// For simplicity, we just remove and return the value
// A full implementation would pop from a stack per key
String value = get(key);
remove(key);
return value;
}

/**
* Clear the MDC stack for the given key.
* This method is required by slf4j 2.x MDCAdapter interface.
*
* @param key the key to identify the stack to clear
*/
@Override
public void clearDequeByKey(String key) {
// For simplicity, we just remove the key
// A full implementation would clear the entire stack for the key
remove(key);
}

/**
* Get a copy of the deque associated with the given key.
* This method is required by slf4j 2.x MDCAdapter interface.
*
* @param key the key to identify the deque
* @return a copy of the deque, or null if no deque exists for the key
*/
@Override
public Deque<String> getCopyOfDequeByKey(String key) {
// For simplicity, we return null as we don't maintain a deque structure
// A full implementation would return a copy of the deque for the key
return null;
}

}


10 changes: 7 additions & 3 deletions trpc-dependencies/trpc-dependencies-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@
<jakarta.xml.bind-api.version>2.3.2</jakarta.xml.bind-api.version>
<javassist.version>3.28.0-GA</javassist.version>
<javax.servlet-api.version>3.1.0</javax.servlet-api.version>

<jsr305.version>3.0.2</jsr305.version>
<logback.version>1.2.13</logback.version>
<logging.log4j.version>2.17.1</logging.log4j.version>

<logback.version>1.5.18</logback.version>
<logging.log4j.version>2.24.3</logging.log4j.version>
<log4j2.ttl.thread.context.map.version>1.3.3</log4j2.ttl.thread.context.map.version>

<maven.gpg.version>3.1.0</maven.gpg.version>
<maven.deploy.version>3.0.0</maven.deploy.version>
<maven.source.version>3.0.1</maven.source.version>
Expand Down Expand Up @@ -133,7 +136,7 @@
<resteasy.version>5.0.6.Final</resteasy.version>
<sentinel-transport-simple-http.version>1.8.6</sentinel-transport-simple-http.version>
<sentinel.version>1.8.6</sentinel.version>
<slf4j.version>1.7.36</slf4j.version>
<slf4j.version>2.0.17</slf4j.version>
<snakeyaml.version>2.0</snakeyaml.version>
<snappy.version>1.1.10.4</snappy.version>
<spring.version>5.3.27</spring.version>
Expand Down Expand Up @@ -568,6 +571,7 @@
<groupId>org.eclipse.jetty</groupId>
<version>${jetty.version}</version>
</dependency>

<dependency>
<artifactId>jetty-servlet</artifactId>
<groupId>org.eclipse.jetty</groupId>
Expand Down
Loading