Browse Source

zones: introduce (private) logger interface

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/12/head
Alejandro Mery 1 year ago
parent
commit
5e5958d22e
  1. 49
      pkg/zones/log.go
  2. 1
      pkg/zones/options.go
  3. 2
      pkg/zones/zones.go

49
pkg/zones/log.go

@ -0,0 +1,49 @@
package zones
import "darvaza.org/slog"
type logger interface {
withDebug() (slog.Logger, bool)
withInfo() (slog.Logger, bool)
debug() slog.Logger
info() slog.Logger
warn(error) slog.Logger
error(error) slog.Logger
}
var (
_ logger = (*Zones)(nil)
)
func (z *Zones) withDebug() (slog.Logger, bool) {
return z.debug().WithEnabled()
}
func (z *Zones) withInfo() (slog.Logger, bool) {
return z.debug().WithEnabled()
}
func (z *Zones) debug() slog.Logger {
return z.log.Debug()
}
func (z *Zones) info() slog.Logger {
return z.log.Info()
}
func (z *Zones) warn(err error) slog.Logger {
l := z.log.Warn()
if err != nil {
l = l.WithField(slog.ErrorFieldName, err)
}
return l
}
func (z *Zones) error(err error) slog.Logger {
l := z.log.Error()
if err != nil {
l = l.WithField(slog.ErrorFieldName, err)
}
return l
}

1
pkg/zones/options.go

@ -69,6 +69,7 @@ func WithLogger(log slog.Logger) ScanOption {
}
opt.Logger = log
m.log = log
return nil
}
}

2
pkg/zones/zones.go

@ -6,6 +6,7 @@ import (
"sort"
"darvaza.org/resolver"
"darvaza.org/slog"
"github.com/gofrs/uuid/v5"
)
@ -141,6 +142,7 @@ func (z *Zone) GatewayIDs() ([]int, int) {
// Zones represents all zones in a cluster
type Zones struct {
dir fs.FS
log slog.Logger
resolver resolver.Resolver
domain string

Loading…
Cancel
Save