config.go 616 B

1234567891011121314151617181920212223242526272829
  1. package logger
  2. import (
  3. "git.linuxforward.com/byom/byom-golang-lib/pkg/errors"
  4. "github.com/sirupsen/logrus"
  5. )
  6. // Config holds the logger configuration
  7. type Config struct {
  8. Level string `yaml:"level"`
  9. Format string `yaml:"format"` // "json" or "text"
  10. NoColor bool `yaml:"no_color"`
  11. }
  12. // Validate implements the config.Validator interface
  13. func (c *Config) Validate() error {
  14. if c.Level == "" {
  15. c.Level = "info"
  16. }
  17. if c.Format == "" {
  18. c.Format = "text"
  19. }
  20. // Validate log level
  21. _, err := logrus.ParseLevel(c.Level)
  22. if err != nil {
  23. return errors.NewConfigError("log.level", err)
  24. }
  25. return nil
  26. }