@@ -3,11 +3,12 @@ package main
3
3
import (
4
4
"flag"
5
5
"fmt"
6
+ "log/slog"
7
+ "os"
8
+
6
9
"github.com/applauseoss/metronomikon/api"
7
10
"github.com/applauseoss/metronomikon/config"
8
11
"github.com/applauseoss/metronomikon/kube"
9
- "log"
10
- "os"
11
12
)
12
13
13
14
var defaultConfigFile = "/etc/metronomikon/config.yaml"
@@ -18,6 +19,15 @@ func main() {
18
19
flag .BoolVar (& debug , "debug" , false , "Enable debug mode" )
19
20
flag .StringVar (& configFile , "config" , "" , fmt .Sprintf ("Path to config file (defaults to %s, if it exists)" , defaultConfigFile ))
20
21
flag .Parse ()
22
+ // Setup logger
23
+ logLevel := slog .LevelInfo
24
+ if debug {
25
+ logLevel = slog .LevelDebug
26
+ }
27
+ logger := slog .New (
28
+ slog .NewJSONHandler (os .Stdout , & slog.HandlerOptions {Level : logLevel }),
29
+ )
30
+ slog .SetDefault (logger )
21
31
// Use default config file path if none was provided and it exists
22
32
if configFile == "" {
23
33
if _ , err := os .Stat (defaultConfigFile ); err == nil {
@@ -27,14 +37,16 @@ func main() {
27
37
// Load config file if specified
28
38
if configFile != "" {
29
39
if err := config .LoadConfig (configFile ); err != nil {
30
- log .Fatalf ("Failed to load config file: %s" , err )
40
+ slog .Error (fmt .Sprintf ("Failed to load config file: %s" , err ))
41
+ os .Exit (1 )
31
42
}
32
43
}
33
44
if err := kube .TestClientConnection (); err != nil {
34
- log .Fatalf ("Failed to connect to Kubernetes API: %s" , err )
45
+ slog .Error (fmt .Sprintf ("Failed to connect to Kubernetes API: %s" , err ))
46
+ os .Exit (1 )
35
47
} else {
36
48
if debug {
37
- log . Print ("Successfully initialized kubernetes client" )
49
+ slog . Info ("Successfully initialized kubernetes client" )
38
50
}
39
51
}
40
52
a := api .New (debug )
0 commit comments