opt.go 894 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package fslog
  2. type outFileConfig struct {
  3. filename string
  4. maxSize int
  5. maxAge int
  6. maxBackups int
  7. localTime bool
  8. Compress bool
  9. }
  10. // FileOutputOpt 文件输出选项
  11. type FileOutputOpt func(*outFileConfig)
  12. func WithFilename(filename string) FileOutputOpt {
  13. return func(c *outFileConfig) {
  14. c.filename = filename
  15. }
  16. }
  17. func WithMaxSize(maxSize int) FileOutputOpt {
  18. return func(c *outFileConfig) {
  19. c.maxSize = maxSize
  20. }
  21. }
  22. func WithMaxAge(maxAge int) FileOutputOpt {
  23. return func(c *outFileConfig) {
  24. c.maxAge = maxAge
  25. }
  26. }
  27. func WithMaxBackups(maxBackups int) FileOutputOpt {
  28. return func(c *outFileConfig) {
  29. c.maxBackups = maxBackups
  30. }
  31. }
  32. func WithLocalTime(localTime bool) FileOutputOpt {
  33. return func(c *outFileConfig) {
  34. c.localTime = localTime
  35. }
  36. }
  37. func WithCompress(compress bool) FileOutputOpt {
  38. return func(c *outFileConfig) {
  39. c.Compress = compress
  40. }
  41. }