options.go 820 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. cap uint
  15. }
  16. func setDefault() options {
  17. return options{
  18. driver: "default",
  19. path: "temp/logs",
  20. level: "warn",
  21. stdout: "default",
  22. }
  23. }
  24. func WithType(s string) Option {
  25. return func(o *options) {
  26. o.driver = s
  27. }
  28. }
  29. func WithPath(s string) Option {
  30. return func(o *options) {
  31. o.path = s
  32. }
  33. }
  34. func WithLevel(s string) Option {
  35. return func(o *options) {
  36. o.level = s
  37. }
  38. }
  39. func WithStdout(s string) Option {
  40. return func(o *options) {
  41. o.stdout = s
  42. }
  43. }
  44. func WithCap(n uint) Option {
  45. return func(o *options) {
  46. o.cap = n
  47. }
  48. }