mdc

MDC Context getting copied to only one thread of ForkJoinPool

风格不统一 提交于 2019-12-11 02:50:48
问题 I want to pass MDC context to threads of the ForkJoinPool as I need to print the requestId populated in the MDCContextMap in all the spawned threads logs for better debugging. I am using the following solution for this: How to use MDC with ForkJoinPool?. I am using the pool as: final ForkJoinPool mdcPool = new MdcForkJoinPool(30); mdcPool.submit(() -> ruleset.getOperationList().parallelStream().forEach(operation -> { log.info("Sample log line"); But from the logs it looks like MDC Context is

Akka intercepting receive with stackable behavior

倾然丶 夕夏残阳落幕 提交于 2019-12-06 09:27:18
Akka and Scala newbie here, please feel free to edit the question as necessary in order to clearly articulate my intent in the domain of Scala and Akka. Before I show code snippets, here's the problem I want to solve: I essentially want to develop a common module for my team to use when they're developing their applications using Akka actors. I want to allow them to mixin a trait which will extend their receive functionality at runtime, mainly for logging purposes. I'm running into compile errors, which I'll explain soon. But first, take for example, a simple main: object Test extends App {

MDC (Mapped Diagnostic Context) Logging in AKKA

空扰寡人 提交于 2019-11-30 22:05:59
I want to implement logback MDC logging on my AKKA application to organize and have a more infomative log; however, I also read that MDC might not work well with AKKA because AKKA has asynchronous logging system (MDC might be stored on a different thread). I used the Custom Dispatcher for MDC Logging defined here hoping to solve my problem but I can't make it work on my application. My application is not a play framework app though. I have a RequestHandler Actor that receives different types of request and delegates it to a RequestSpecificHandler Actor which will process it. class

How to use MDC with ForkJoinPool?

半世苍凉 提交于 2019-11-30 09:27:54
Following up on How to use MDC with thread pools? how can one use MDC with a ForkJoinPool ? Specifically, I how can one wrap a ForkJoinTask so MDC values are set before executing a task? The following seems to work for me: import java.lang.Thread.UncaughtExceptionHandler; import java.util.Map; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinTask; import java.util.concurrent.atomic.AtomicReference; import org.slf4j.MDC; /** * A {@link ForkJoinPool} that inherits MDC contexts from the thread that queues a task. * * @author Gili Tzabari */ public final class

How to use MDC with ForkJoinPool?

£可爱£侵袭症+ 提交于 2019-11-29 14:19:50
问题 Following up on How to use MDC with thread pools? how can one use MDC with a ForkJoinPool ? Specifically, I how can one wrap a ForkJoinTask so MDC values are set before executing a task? 回答1: The following seems to work for me: import java.lang.Thread.UncaughtExceptionHandler; import java.util.Map; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.ForkJoinTask; import java.util.concurrent.atomic.AtomicReference; import org.slf4j.MDC; /** * A {@link ForkJoinPool} that

Scala Akka Logging with SLF4J MDC

孤街浪徒 提交于 2019-11-29 02:29:21
I'm configuring my Akka application to use the SLF4J logger as specified here: http://doc.akka.io/docs/akka/2.3.4/scala/logging.html Underneath the hood, I'm depending on Logback to do the logging. I'm developing a common module for logging purposes that users can use in their actor systems. Mainly, I'm creating a trait they can mixin. I have a trait that does this: I have something as such: trait ActorLogger { val log: DiagnosticLoggingAdapter = Logging(this); } I have some extra logic which will add MDC values to the DiagnosticLoggingAdapter's MDC. The problem is now this: I expose a

Using MDC in log4j to dynamically name the log file

让人想犯罪 __ 提交于 2019-11-28 07:04:42
Is it possible some how to use MDC to name the log file at run time. I have a single web application which is being called by different names at the same time using tomcat docbase. So i need to have separate log files for each of them. This can be accomplished in Logback , the successor to Log4J. Logback is intended as a successor to the popular log4j project, picking up where log4j leaves off. See the documentation for Sifting Appender The SiftingAppender is unique in its capacity to reference and configure nested appenders. In the above example, within the SiftingAppender there will be

Scala Akka Logging with SLF4J MDC

末鹿安然 提交于 2019-11-27 16:47:06
问题 I'm configuring my Akka application to use the SLF4J logger as specified here: http://doc.akka.io/docs/akka/2.3.4/scala/logging.html Underneath the hood, I'm depending on Logback to do the logging. I'm developing a common module for logging purposes that users can use in their actor systems. Mainly, I'm creating a trait they can mixin. I have a trait that does this: I have something as such: trait ActorLogger { val log: DiagnosticLoggingAdapter = Logging(this); } I have some extra logic which

Using MDC in log4j to dynamically name the log file

这一生的挚爱 提交于 2019-11-27 01:42:20
问题 Is it possible some how to use MDC to name the log file at run time. I have a single web application which is being called by different names at the same time using tomcat docbase. So i need to have separate log files for each of them. 回答1: This can be accomplished in Logback, the successor to Log4J. Logback is intended as a successor to the popular log4j project, picking up where log4j leaves off. See the documentation for Sifting Appender The SiftingAppender is unique in its capacity to

How to use MDC with thread pools?

我的梦境 提交于 2019-11-26 06:55:50
问题 In our software we extensively use MDC to track things like session IDs and user names for web requests. This works fine while running in the original thread. However, there\'s a lot of things that need to be processed in the background. For that we use the java.concurrent.ThreadPoolExecutor and java.util.Timer classes along with some self-rolled async execution services. All these services manage their own thread pool. This is what Logback\'s manual has to say about using MDC in such an