之前写过一篇文章日志的艺术(The art of logging),提到了输出日志的时候记录上下文信息的重要性,我认为上下文信息包括: when:log事件发生的时间 where:log事件发生在哪个模块(文件.函数) how important:log 事件的紧急程度 who:事件产生者的唯一标识 what:具体的事件内容,以及其他所必须的上下文信息 其中,when.where.how important都很容易通过logging框架自动包含,但是who(事件生产者的唯一标识)就不能框架自动填
logging example Level When it's used Numeric value DEBUG Detailed information, typically of interest only when diagnosing problems. 10 INFO Confirmation that things are working as expected. 20 WARNING An indication that something unexpected happened,