什么是 NDC 日志以及我们如何在我们的应用程序中使用它以及它的意义是什么
什么是 NDC 日志以及我们如何在我们的应用程序中使用它以及它的意义是什么......
what is the NDC logs and how we can use it in our application and what is the significance of that...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
嵌套诊断上下文特定于线程。
常见用途是记录每个会话的信息(如果会话使用一个线程),因此您可以记录原始客户端、用户名等以及其他横切属性,而无需:
另请参阅 Log4j 的映射诊断上下文。
Nested Diagnostic Contexts are particular to a thread.
Common uses are for recording info per-session (if one thread is used for a session), so you can log the originating client, username etc. and other cross-cutting attributes without:
PatternLayout
is suitably configured.See also Log4j's Mapped Diagnostic Contexts.
NDC 代表“嵌套诊断上下文”,它是 log4j 的一个功能。 log4j 最常见的用法只是记录内容,而不指示它属于哪个客户端请求,其结果是,当您的应用程序在生产环境中运行并发请求时,所有请求的所有日志消息都混杂在一起日志文件并告诉谁做了什么是不可能的。 NDC 允许您将日志消息标记为属于特定客户端,以便您可以区分谁在做什么,而无需为每个客户端设置单独的记录器。
NDC stands for "Nested Diagnostic Contexts", it's a feature of log4j. The most common usage of log4j is just to log stuff without any indication of what client request it was part of, with the result that, when your application runs in production with concurrent requests, all the log messages for all the requests are jumbled together in the log file and telling who did what is impossible. NDC allows you to mark log messages as belonging to particular clients so that you can distinguish who is doing what, without having separate loggers for each client.
Logger 通常在代码中静态定义,这使得 log 有时难以理解。
NDC 允许动态地
push
一个参数,该参数将显示在线程发出的每个后续日志行中,直到它被pop
ped。如果您想要如下日志,则很有用:(
免责声明:我不记得确切的格式)
仅使用
a,b,c,d
很难理解哪个线程执行什么操作。如果您动态地push
和pop
请求ID,那么就更容易遵循。也可用于其他类型的上下文信息。Logger are usually statically defined in the code, which make log sometimes hard to understand.
The NDC allows the dynamically
push
a parameter that will be displayed in every subsequent log line issued by the thread, until it ispop
ped.Useful if you want a log like:
(Disclaimer: I don't remember the exact formatting)
With just
a,b,c,d
it's hard to understand which thread does what. If youpush
andpop
the request id dynamically, then it's easier to follow. Can also be used for other kinds of contextual information.