综合
log 标准库
Posts on 煎é±0 次浏览
日志 输出 2018/09/28 20:03:08 EDDYCJY Blog... 构成 [日期]<空格>[时分秒]<空格>[内容]<\n> 源码剖析 Logger type Logger struct { mu sync.Mutex prefix string flag int out io.Writer buf []byte } mu:互斥锁,用于确保原子的写入 prefix:每行需写入的日志前缀内容 flag:设置日志辅助信息(时间、文件名、行号)的写入。可选如下标识位: const ( Ldate = 1 << iota // value: 1 Ltime // value: 2 Lmicroseconds // value: 4 Llongfile // value: 8 Lshortfile // value: 16 LUTC // value: 32 LstdFlags = Ldate | Ltime // value: 3 ) Ldate:当地时区的格式化日期:2009/01/23 Ltime:当地时区的格式化时间:01:23:23 Lmicroseconds:在 Ltime 的基础上,增加微秒的时间数值显示 Llongfile:完整的文件名和行号:/a/b/c/d.
原文:https://eddycjy.com/posts/go/pkg/2018-09-28-log/