From 7c4566f1169b8280769ef418bc33b28984496168 Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Wed, 29 Jul 2020 14:33:36 -0400 Subject: [PATCH] api: Use a Logger instead of an io.Writer in api.Watch So that we can pass around only a Logger, not a LogOutput --- agent/agent.go | 2 +- api/watch/plan.go | 6 ++++-- api/watch/watch.go | 6 +++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index eac75560b..76cc03de6 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -1263,7 +1263,7 @@ func (a *Agent) reloadWatches(cfg *config.RuntimeConfig) error { httpConfig := wp.Exempt["http_handler_config"].(*watch.HttpHandlerConfig) wp.Handler = makeHTTPWatchHandler(a.logger, httpConfig) } - wp.LogOutput = a.LogOutput + wp.Logger = a.logger.Named("watch") addr := config.Address if config.Scheme == "https" { diff --git a/api/watch/plan.go b/api/watch/plan.go index 6cf11157c..f3b7981fb 100644 --- a/api/watch/plan.go +++ b/api/watch/plan.go @@ -31,8 +31,10 @@ func (p *Plan) Run(address string) error { // Run is used to run a watch plan func (p *Plan) RunWithConfig(address string, conf *consulapi.Config) error { - // Create the logger - logger := newWatchLogger(p.LogOutput) + logger := p.Logger + if logger == nil { + logger = newWatchLogger(p.LogOutput) + } // Setup the client p.address = address diff --git a/api/watch/watch.go b/api/watch/watch.go index 09ee15edd..1dce25291 100644 --- a/api/watch/watch.go +++ b/api/watch/watch.go @@ -8,6 +8,7 @@ import ( "time" consulapi "github.com/hashicorp/consul/api" + "github.com/hashicorp/go-hclog" "github.com/mitchellh/mapstructure" ) @@ -29,7 +30,10 @@ type Plan struct { // on index param. To support hash based watches, set HybridHandler instead. Handler HandlerFunc HybridHandler HybridHandlerFunc - LogOutput io.Writer + + Logger hclog.Logger + // Deprecated: use Logger + LogOutput io.Writer address string client *consulapi.Client