Flags额外特性

flags用于控制日志组件的额外特性开关,这些属性使用常量进行组合控制,包括:

  1. F_ASYNC = 1 << iota // 开启日志异步输出
  2. F_FILE_LONG // 打印调用行号信息,完整绝对路径,例如:/a/b/c/d.go:23
  3. F_FILE_SHORT // 打印调用行号信息,仅打印文件名,例如:d.go:23,覆盖 F_FILE_LONG.
  4. F_TIME_DATE // 打印当前日期,如:2009-01-23
  5. F_TIME_TIME // 打印当前时间,如:01:23:23
  6. F_TIME_MILLI // 打印当前时间+毫秒,如:01:23:23.675
  7. F_TIME_STD = F_TIME_DATE | F_TIME_MILLI // (默认)打印当前日期+时间+毫秒,如:2009-01-23 01:23:23.675

使用示例:

  1. package main
  2. import (
  3. "github.com/gogf/gf/g/os/glog"
  4. )
  5. func main() {
  6. l := glog.New()
  7. l.SetFlags(glog.F_TIME_TIME|glog.F_FILE_SHORT)
  8. l.Println("time and short line number")
  9. l.SetFlags(glog.F_TIME_MILLI|glog.F_FILE_LONG)
  10. l.Println("time with millisecond and long line number")
  11. l.SetFlags(glog.F_TIME_STD|glog.F_FILE_LONG)
  12. l.Println("standard time format and long line number")
  13. }

执行后,终端输出结果为:

  1. 09:25:49 glog_flags.go:10: time and short line number
  2. 09:25:49.310 /Users/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/geg/os/glog/glog_flags.go:12: time with millisecond and long line number
  3. 2019-05-23 09:25:49.310 /Users/john/Workspace/Go/GOPATH/src/github.com/gogf/gf/geg/os/glog/glog_flags.go:14: standard time format and long line number