怎么打日志

Thumbnail

需要解决的问题: 业务日志打太乱,没有位置和格式约束 什么情况打日志,如何避免滥用,提高日志作用 打日志最佳实践 Dropwizard 列出的打日志原则: Be human readable. Be machine parsable. Be easy for sleepy ops folks to figure out why things are pear-shaped at 3:30AM using standard UNIXy tools like tail and grep. eg.: TRACE [2010-04-06 06:42:35,271] com.example.dw.Thing: Contemplating doing a thing. DEBUG [2010-04-06 06:42:35,274] com.example.dw.Thing: About to do a thing. INFO [2010-04-06 06:42:35,274] com.example.dw.Thing: Doing a thing WARN [2010-04-06 06:42:35,275] com.example.dw.Thing: Doing a thing ERROR [2010-04-06 06:42:35,275] com.example.dw.Thing: This may get ugly. ! java.lang.RuntimeException: oh noes! ! at com.example.dw.Thing.run(Thing.java:16) ! splunk 的最佳实践: 使用清晰的键值对:key1=val1, key2=val2 对开发者易读 全部添加时间戳 使用唯一标记,比如 user_id, transaction_id 使用文本 使用开发者...

2015-10-18 · alswl