java.util.logging.Logger.log()是责任链模式吗? [英] Is java.util.logging.Logger.log() is an chain of responsibility pattern?

查看:159
本文介绍了java.util.logging.Logger.log()是责任链模式吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java.util.logging.Logger.log()是一个责任链模式吗?如果是的话,日志方法调用如何链接到下一个调用?

Is java.util.logging.Logger.log() is a chain of responsibility pattern?If so how log method call is getting chained for the next call?

推荐答案

以下是相关的代码

// Post the LogRecord to all our Handlers, and then to
// our parents' handlers, all the way up the tree.

Logger logger = this;
while (logger != null) {
    Handler targets[] = logger.getHandlers();

    //...

    if (!logger.getUseParentHandlers()) {
      break;
    }

    logger = logger.getParent();
}
}

您可以看到每个日志记录都传递给每个 Handler 分配给给定的记录器,如果 useParentHandlers true ,将相同的算法一直应用到父节点直到顶部。

As you can see each logging record is passed to every Handler assigned to a given logger and, if useParentHandlers is true, the same algorithm is applied to parent all the way up to the top.

因此,从本质上讲,这是一种责任链模式,其中链中的每个元素都可以处理碎片的请求。

So essentially this is a chain of responsibility pattern where each element in the chain might handle piece of the request.

这篇关于java.util.logging.Logger.log()是责任链模式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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