Skip to content

Instantly share code, notes, and snippets.

View pismy's full-sized avatar

Pierre Smeyers pismy

  • Toulouse, FRANCE
View GitHub Profile
@pismy
pismy / ThreadPoolTaskExecutorWithMdcPropagation.java
Created January 12, 2016 09:15
SLF4J Tool: ThreadPoolExecutor that propagates MDC from calling thread to executor thread
import java.util.Map;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@pismy
pismy / HttpRequestHandlerWithMdcPropagation.java
Last active September 20, 2018 07:23
SLF4J & Apache Http tool: propagates MDC context over client Http requests (suitable for micro-services architecture)
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.http.HttpException;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HttpContext;
@pismy
pismy / CustomThrowableConverterWithHash.java
Last active January 1, 2019 15:27
SLF4J Tools: Generate unique error signatures and prepend it to your stack trace
package com.orange.experts.utils.logging.logback;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import ch.qos.logback.classic.pattern.ThrowableHandlingConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.IThrowableProxy;
@pismy
pismy / SessionIdFilter.java
Last active January 12, 2016 08:52
SLF4J Tool: a web component that adds the session id to the logging context (MDC)
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpServletRequest;
@pismy
pismy / RequestIdFilter.java
Last active January 12, 2016 08:53
SLF4J Tool: A servlet filter that adds a generated unique request id to the logging context (MDC)
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;