1
0

logger_config.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package logger
  2. import (
  3. "log/slog"
  4. )
  5. const (
  6. defaultStdoutLogEnabled = true
  7. )
  8. type Config struct {
  9. stdoutLogEnabled bool
  10. fileLogEnabled bool
  11. emailLogEnabled bool
  12. // INFO by default
  13. stdoutLogLevel slog.Level
  14. fileLogLevel slog.Level
  15. emailLogLevel slog.Level
  16. }
  17. type ConfigOption func(*Config)
  18. type ConfigOptions []ConfigOption
  19. func (s *ConfigOptions) Add(option ConfigOption) {
  20. *s = append(*s, option)
  21. }
  22. func WithStdoutLogEnabled(enabled bool) ConfigOption {
  23. return func(s *Config) {
  24. s.stdoutLogEnabled = enabled
  25. }
  26. }
  27. func WithFileLogEnabled(enabled bool) ConfigOption {
  28. return func(s *Config) {
  29. s.fileLogEnabled = enabled
  30. }
  31. }
  32. func WithEmailLogEnabled(enabled bool) ConfigOption {
  33. return func(s *Config) {
  34. s.emailLogEnabled = enabled
  35. }
  36. }
  37. func WithStdoutLogLevel(level slog.Level) ConfigOption {
  38. return func(s *Config) {
  39. s.stdoutLogLevel = level
  40. }
  41. }
  42. func WithFileLogLevel(level slog.Level) ConfigOption {
  43. return func(s *Config) {
  44. s.fileLogLevel = level
  45. }
  46. }
  47. func WithEmailLogLevel(level slog.Level) ConfigOption {
  48. return func(s *Config) {
  49. s.emailLogLevel = level
  50. }
  51. }