记录多线程应用程序中的活动 [英] Logging activities in multithreaded applications

查看:95
本文介绍了记录多线程应用程序中的活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java中有一个分层应用程序,它有一个多线程数据访问层,可以从不同的点调用。对该层的单次调用可能会产生多个线程来并行化对数据库的请求。

I have a layered application in Java which has a multi thread data access layer which is invoked from different points. A single call to this layer is likely to spawn several threads to parallelize requests to the DB.

我正在寻找的是一个日志工具,它允许我定义由各种线程组成的活动。因此,数据访问层中的相同方法应根据其调用者记录不同的输出。将不同输出分组以总结操作总成本的能力也很重要。

What I'm looking for is a logging tool that would allow me to define "activities" that are composed by various threads. Therefore, the same method in the data access layer should log different outputs depending on its caller. The ability to group different outputs to summarize the total cost of an operation is also important.

虽然应用程序是Java语言,但语言不是限制;我需要的是设计指南,以便最终实现它。我们目前正在使用log4j,但无法从中获得此行为。

Although the application is in Java, language is not a restriction; what I need are the design guidelines so to eventually implement it. We are currently using log4j, but can't get this behaviour from it.

推荐答案

您还应该看一下< log4j的href =http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/NDC.html =nofollow noreferrer>嵌套诊断上下文功能。针对不同的呼叫者向记录器推送不同的上下文可能会为您提供帮助。

You should also have a look at the nested diagnostic context feature of log4j. Pushing different contexts to the logger for different callers might do the trick for you.

这篇关于记录多线程应用程序中的活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆