1
0

options.go 928 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * @Author: lwnmengjing
  3. * @Date: 2021/6/10 10:26 上午
  4. * @Last Modified by: lwnmengjing
  5. * @Last Modified time: 2021/6/10 10:26 上午
  6. */
  7. package logger
  8. type Option func(*options)
  9. type options struct {
  10. driver string
  11. path string
  12. level string
  13. stdout string
  14. maxDays int
  15. cap uint
  16. }
  17. func setDefault() options {
  18. return options{
  19. driver: "default",
  20. path: "temp/logs",
  21. level: "warn",
  22. stdout: "default",
  23. maxDays: 7,
  24. }
  25. }
  26. func WithType(s string) Option {
  27. return func(o *options) {
  28. o.driver = s
  29. }
  30. }
  31. func WithPath(s string) Option {
  32. return func(o *options) {
  33. o.path = s
  34. }
  35. }
  36. func WithLevel(s string) Option {
  37. return func(o *options) {
  38. o.level = s
  39. }
  40. }
  41. func WithStdout(s string) Option {
  42. return func(o *options) {
  43. o.stdout = s
  44. }
  45. }
  46. func WithCap(n uint) Option {
  47. return func(o *options) {
  48. o.cap = n
  49. }
  50. }
  51. func WithMaxDays(n int) Option {
  52. return func(o *options) {
  53. o.maxDays = n
  54. }
  55. }