You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I just want to clear MDC content when filter chain is completed. I realized after clearing MDC in LoggingFilter class, Quarkus access logs do not log the content I put in. What I expect is that it should be logged, then ContainerResponseFilter should be triggered. Somehow logging of quarkus access log happens after respose filter of JAX-RS
Do you have any idea how can I change the order?
I want to log MDC content in quarkus access log, then clear the MDC.
@Path("/hello-resteasy")
public class GreetingResource {
java.util.logging.Logger logger = LogManager.getLogManager().getLogger(GreetingResource.class.getName());
@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
logger.info("a log message");
return "Hello RESTEasy";
}
}
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.ext.Provider;
import org.jboss.logging.MDC;
@Provider
public class LoggingFilter implements ContainerRequestFilter, ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext requestContext) {
MDC.put("test", "testValue");
}
@Override
public void filter(final ContainerRequestContext requestContext, final ContainerResponseContext responseContext) {
MDC.clear();
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I just want to clear MDC content when filter chain is completed. I realized after clearing MDC in LoggingFilter class, Quarkus access logs do not log the content I put in. What I expect is that it should be logged, then ContainerResponseFilter should be triggered. Somehow logging of quarkus access log happens after respose filter of JAX-RS
Do you have any idea how can I change the order?
I want to log MDC content in quarkus access log, then clear the MDC.
logs =>
{"timestamp":"2023-11-24T16:06:08.422+03:00","sequence":1994,"loggerClassName":"org.jboss.logmanager.Logger","loggerName":"org.acme.GreetingResource","level":"INFO","message":"a log message","threadName":"executor-thread-0","threadId":85,"mdc":{"test":"testValue"},"ndc":"","hostName":"hj9xgjxrql","processName":"code-with-quarkus-dev.jar","processId":12056}
{"timestamp":"2023-11-24T16:06:08.434+03:00","sequence":1995,"loggerClassName":"org.jboss.logging.Logger","loggerName":"io.quarkus.http.access-log","level":"INFO","message":"127.0.0.1 - - 24/Nov/2023:16:06:08 +0300 "GET /hello-resteasy HTTP/1.1" 200 14","threadName":"executor-thread-0","threadId":85**,"mdc":{},**"ndc":"","hostName":"hj9xgjxrql","processName":"code-with-quarkus-dev.jar","processId":12056}
Beta Was this translation helpful? Give feedback.
All reactions