api: Use a Logger instead of an io.Writer in api.Watch

So that we can pass around only a Logger, not a LogOutput
This commit is contained in:
Daniel Nephin 2020-07-29 14:33:36 -04:00
parent c7c941811d
commit 7c4566f116
3 changed files with 10 additions and 4 deletions

View File

@ -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" {

View File

@ -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

View File

@ -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