Skip to content

Commit

Permalink
fix: add Resolver.String so logs don't use Go's default format
Browse files Browse the repository at this point in the history
  • Loading branch information
ThinkChaos committed Jan 14, 2024
1 parent 7abbaef commit 780c2a2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions resolver/noop_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ func (NoOpResolver) Type() string {
return "noop"
}

// String implements `fmt.Stringer`.
func (r NoOpResolver) String() string {
return r.Type()

Check warning on line 26 in resolver/noop_resolver.go

View check run for this annotation

Codecov / codecov/patch

resolver/noop_resolver.go#L25-L26

Added lines #L25 - L26 were not covered by tests
}

// IsEnabled implements `config.Configurable`.
func (NoOpResolver) IsEnabled() bool {
return true
Expand Down
2 changes: 1 addition & 1 deletion resolver/parallel_best_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (r *ParallelBestResolver) String() string {

upstreams := make([]string, len(resolvers))
for i, s := range resolvers {
upstreams[i] = fmt.Sprintf("%s", s.resolver)
upstreams[i] = s.resolver.String()
}

return fmt.Sprintf("%s upstreams '%s (%s)'", r.Type(), r.cfg.Name, strings.Join(upstreams, ","))
Expand Down
6 changes: 6 additions & 0 deletions resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func newRequestWithClientID(question string, rType dns.Type, ip, requestClientID
// Resolver generic interface for all resolvers
type Resolver interface {
config.Configurable
fmt.Stringer

// Type returns a short, user-friendly, name for the resolver.
//
Expand Down Expand Up @@ -193,6 +194,11 @@ func (t *typed) Type() string {
return t.typeName
}

// String implements `fmt.Stringer`.
func (t *typed) String() string {
return t.Type()
}

func (t *typed) log() *logrus.Entry {
return log.PrefixedLog(t.Type())
}
Expand Down
2 changes: 1 addition & 1 deletion resolver/strict_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (r *StrictResolver) String() string {

upstreams := make([]string, len(resolvers))
for i, s := range resolvers {
upstreams[i] = fmt.Sprintf("%s", s.resolver)
upstreams[i] = s.resolver.String()
}

return fmt.Sprintf("%s upstreams '%s (%s)'", strictResolverType, r.cfg.Name, strings.Join(upstreams, ","))
Expand Down

0 comments on commit 780c2a2

Please sign in to comment.