从源码与官方文档看之Handle篇(二)

292 阅读2分钟

携手创作,共同成长!这是我参与「掘金日新计划 · 8 月更文挑战」的第19天,点击查看活动详情 >> 希望大家可以帮忙点个赞,谢谢!

前言

上一篇我们根据官方注释解读Handle的一些基本属性,这一篇我们接着慢慢阐述。

正篇

首先我们接着看下面官方给Handle的一些参数:

// We're using volatile here to avoid synchronizing getters, which
// would prevent other threads from calling isLoggable()
// while publish() is executing.
// On the other hand, setters will be synchronized to exclude concurrent
// execution with more complex methods, such as StreamHandler.publish().
// We wouldn't want 'level' to be changed by another thread in the middle
// of the execution of a 'publish' call.
private volatile Filter filter;
private volatile Formatter formatter;
private volatile Level logLevel = Level.ALL;
private volatile ErrorManager errorManager = new ErrorManager();
private volatile String encoding;

依次来看,他们分别是 注释说了一些条件前提与理由:说使用 volatile 来避免同步 getters;阻止其他线程调用 isLoggable();当 publish() 正在执行时;setters 将被同步以排除并发;推荐使用更复杂的方法执行,例如 StreamHandler.publish();官方还不希望 'level' 被中间的另一个线程改变;要在执行“发布”调用
1.过滤器 用于Logger和Handler控制日志级别
2.格式化 可以用于格式化LogRecords
3.日志级别标签
4.错误管理 翻译的大意就是这是可以附加到 Handlers 用于处理 Logging 期间发生在 Handler 上的任何错误。
在处理日志输出时,如果 Handler 遇到问题,则 Handler 应该调用其关联的 ErrorManager,而不是向日志调用的发出者抛出异常。
5.编码 没找到官方的解释,所以暂时先搁置一下,额,我们继续往下看


// Package private support for security checking.  When sealed
// is true, we access check updates to the class.
boolean sealed = true;

这个属性根据翻译来看,大意是为安全检查打包私有支持。 密封时。
且该属性为真的时候,我们就可以访问检查更新类。
(未完待续)

小结

我们已经看完了方法之前的一些变量和方法引用,下一篇将开始具体讲述方法的实现。