Skip to content

Commit

Permalink
Add additional fields to log messages
Browse files Browse the repository at this point in the history
Makes it a lot easier to know what is actually running.
  • Loading branch information
eest committed Sep 25, 2024
1 parent 321b917 commit 4b5cbad
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ import (

const dawgNotFound = -1

// version set at build time with -ldflags="-X github.com/dnstapir/edm/pkg/runner.version=v0.0.1"
var version = "unspecified"

type edmStatusBits uint64

func (dsb *edmStatusBits) String() string {
Expand Down Expand Up @@ -675,8 +678,19 @@ func (edm *dnstapMinimiser) registerFSWatcher(filename string, callback func(str

func Run() {

defaultHostname := "edm-hostname-unknown"
hostname, err := os.Hostname()
if err != nil {
fmt.Fprintf(os.Stderr, "unable to get hostname, using '%s'", defaultHostname)
hostname = defaultHostname
}

// Logger used for all output
logger := slog.New(slog.NewJSONHandler(os.Stderr, nil))
logger = logger.With("service", "edm")
logger = logger.With("hostname", hostname)
logger = logger.With("go_version", runtime.Version())
logger = logger.With("version", version)

// This makes any calls to the standard "log" package to use slog as
// well
Expand Down

0 comments on commit 4b5cbad

Please sign in to comment.