opt_file.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package logger
  2. type OutFileOptions struct {
  3. filename string
  4. maxSize int
  5. maxAge int
  6. maxBackups int
  7. localTime bool
  8. compress bool
  9. }
  10. func (options OutFileOptions) Filename() string {
  11. return options.filename
  12. }
  13. func (options OutFileOptions) MaxSize() int {
  14. return options.maxSize
  15. }
  16. func (options OutFileOptions) MaxAge() int {
  17. return options.maxAge
  18. }
  19. func (options OutFileOptions) MaxBackups() int {
  20. return options.maxBackups
  21. }
  22. func (options OutFileOptions) LocalTime() bool {
  23. return options.localTime
  24. }
  25. func (options OutFileOptions) Compress() bool {
  26. return options.compress
  27. }
  28. // FileOutputOpt 文件输出选项
  29. type FileOutputOpt func(*OutFileOptions)
  30. func WithFilename(filename string) FileOutputOpt {
  31. return func(c *OutFileOptions) {
  32. c.filename = filename
  33. }
  34. }
  35. func WithMaxSize(maxSize int) FileOutputOpt {
  36. return func(c *OutFileOptions) {
  37. c.maxSize = maxSize
  38. }
  39. }
  40. func WithMaxAge(maxAge int) FileOutputOpt {
  41. return func(c *OutFileOptions) {
  42. c.maxAge = maxAge
  43. }
  44. }
  45. func WithMaxBackups(maxBackups int) FileOutputOpt {
  46. return func(c *OutFileOptions) {
  47. c.maxBackups = maxBackups
  48. }
  49. }
  50. func WithLocalTime(localTime bool) FileOutputOpt {
  51. return func(c *OutFileOptions) {
  52. c.localTime = localTime
  53. }
  54. }
  55. func WithCompress(compress bool) FileOutputOpt {
  56. return func(c *OutFileOptions) {
  57. c.compress = compress
  58. }
  59. }