log4j NDC: 日志里的MVC

用NDC可以实现:

  1. 程序里不直接调用log语句log具体的内容,而是把可能需要log的关键值放到线程的context中 (程序=Controller, 关键值=M)

  2. log4j的配置文件再通过EL选取要log的关键值 (View)

NDC = Nested Diagnostic Context

还有一个类似的,叫MDC

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.