Skip to content

Commit

Permalink
update to consul's new logging setup
Browse files Browse the repository at this point in the history
Consujl moved from logger -> logging and incorporated hclog but
otherwise it is pretty much the same.

Changes mostly involved swapping out our adaptations to their old
version not using hclog.
  • Loading branch information
eikenb committed May 26, 2022
1 parent 0086642 commit d959f58
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 29 deletions.
22 changes: 9 additions & 13 deletions check.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,14 @@ func (c *CheckRunner) updateCheckHTTP(latestCheck *api.HealthCheck, checkHash ty
tlsConfig.ServerName = definition.TLSServerName

http := &consulchecks.CheckHTTP{
Notify: c,
CheckID: checkHash,
HTTP: definition.HTTP,
Header: definition.Header,
Method: definition.Method,
Interval: definition.IntervalDuration,
Timeout: definition.TimeoutDuration,
Logger: c.logger.StandardLogger(&hclog.StandardLoggerOptions{
InferLevels: true,
}),
Notify: c,
CheckID: checkHash,
HTTP: definition.HTTP,
Header: definition.Header,
Method: definition.Method,
Interval: definition.IntervalDuration,
Timeout: definition.TimeoutDuration,
Logger: c.logger,
TLSClientConfig: tlsConfig,
}

Expand Down Expand Up @@ -161,9 +159,7 @@ func (c *CheckRunner) updateCheckTCP(latestCheck *api.HealthCheck, checkHash typ
TCP: definition.TCP,
Interval: definition.IntervalDuration,
Timeout: definition.TimeoutDuration,
Logger: c.logger.StandardLogger(&hclog.StandardLoggerOptions{
InferLevels: true,
}),
Logger: c.logger,
}

if check, checkExists := c.checks[checkHash]; checkExists {
Expand Down
22 changes: 6 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"syscall"

"github.com/hashicorp/consul-esm/version"
"github.com/hashicorp/consul/logger"
"github.com/hashicorp/consul/logging"
"github.com/hashicorp/go-hclog"
"github.com/mitchellh/cli"
)
Expand Down Expand Up @@ -39,7 +39,6 @@ func main() {
}

err := f.Parse(os.Args[1:])

if err != nil {
if err != flag.ErrHelp {
fmt.Printf("error parsing flags: %v", err)
Expand All @@ -60,26 +59,16 @@ func main() {
}

// Set up logging.
logConfig := &logger.Config{
logConfig := logging.Config{
Name: "consul-esm",
LogLevel: config.LogLevel,
EnableSyslog: config.EnableSyslog,
SyslogFacility: config.SyslogFacility,
}
ui := &cli.BasicUi{Writer: os.Stdout, ErrorWriter: os.Stderr}
_, gatedWriter, _, logOutput, ok := logger.Setup(logConfig, ui)
if !ok {
logger, err := logging.Setup(logConfig, os.Stdout)
if err != nil {
os.Exit(ExitCodeError)
}
logger := hclog.New(&hclog.LoggerOptions{
Name: "consul-esm",
Level: hclog.LevelFromString(config.LogLevel),
Output: logOutput,
IncludeLocation: true,
JSONFormat: config.LogJSON,
})

gatedWriter.Flush()

agent, err := NewAgent(config, logger)
if err != nil {
panic(err)
Expand All @@ -99,6 +88,7 @@ func main() {
signal.Notify(signalCh)
go handleSignals(agent.logger, signalCh, agent)

ui := cli.BasicUi{Writer: os.Stdout, ErrorWriter: os.Stderr}
ui.Output("Consul ESM running!")
if config.Datacenter == "" {
ui.Info(fmt.Sprintf(" Datacenter: (default)"))
Expand Down

0 comments on commit d959f58

Please sign in to comment.