options.go 955 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package logger
  2. // LogLevel 日志级别类型
  3. type LogLevel string
  4. const (
  5. DebugLevel LogLevel = "debug"
  6. InfoLevel LogLevel = "info"
  7. WarnLevel LogLevel = "warn"
  8. ErrorLevel LogLevel = "error"
  9. )
  10. // Options 日志配置选项
  11. type Options struct {
  12. Level LogLevel // 日志级别
  13. Format string // 输出格式: json, console
  14. OutputPath string // 输出路径: 文件路径,空则输出到stdout
  15. MaxSize int // 日志文件最大大小(MB)
  16. MaxBackups int // 保留的旧日志文件最大数量
  17. MaxAge int // 保留旧日志文件的最大天数
  18. Compress bool // 是否压缩归档的日志文件
  19. Caller bool // 是否显示调用者信息
  20. }
  21. // DefaultOptions 默认配置
  22. func DefaultOptions() *Options {
  23. return &Options{
  24. Level: InfoLevel,
  25. Format: "console",
  26. OutputPath: "",
  27. MaxSize: 100,
  28. MaxBackups: 7,
  29. MaxAge: 30,
  30. Compress: true,
  31. Caller: true,
  32. }
  33. }