-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (30 loc) · 981 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"fmt"
"log/slog"
"os"
"runtime"
"github.com/dnstapir/edm/cmd"
)
// version set at build time with -ldflags="-X main.version=v0.0.1"
var version = "undefined"
func main() {
defaultHostname := "edm-hostname-unknown"
hostname, err := os.Hostname()
if err != nil {
fmt.Fprintf(os.Stderr, "unable to get hostname, using '%s'", defaultHostname)
hostname = defaultHostname
}
// loggerLevel controls the global logging level for the application
loggerLevel := new(slog.LevelVar) // Info by default
// Logger used for all output
logger := slog.New(slog.NewJSONHandler(os.Stderr, &slog.HandlerOptions{Level: loggerLevel}))
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
slog.SetDefault(logger)
cmd.Execute(logger, loggerLevel)
}