@@ -7,24 +7,38 @@ import (
77 "os/signal"
88 "syscall"
99
10- "github.com/Azure/azure-container-networking/cns/logger"
10+ "github.com/Azure/azure-container-networking/cns/logger/v2"
11+ cores "github.com/Azure/azure-container-networking/cns/logger/v2/cores"
12+ "go.uber.org/zap"
1113)
1214
1315var (
1416 version = "unknown"
1517 configPath = flag .String ("config" , "/etc/cns/cns-config.json" , "Path to CNS configuration file" )
18+ logLevel = flag .String ("log-level" , "info" , "Log level (debug, info, warn, error)" )
1619)
1720
1821func main () {
1922 flag .Parse ()
2023
21- // Initialize logging for the CNI telemetry sidecar
22- logger .InitLogger ("azure-cns-cni-telemetry-sidecar" , 1 , 1 , "/var/log/azure-cns-telemetry" )
23- defer logger .Close ()
24+ // Initialize main logger
25+ zapLogger , cleanup , err := logger .New (& logger.Config {
26+ Level : * logLevel ,
27+ File : & cores.FileConfig {
28+ Filepath : "/var/log/azure-cni-telemetry-sidecar.log" ,
29+ },
30+ })
31+ if err != nil {
32+ panic ("Failed to initialize logger: " + err .Error ())
33+ }
34+ defer cleanup ()
2435
25- logger .Printf ("Starting Azure CNI Telemetry Sidecar v%s" , version )
36+ zapLogger .Info ("Starting Azure CNI Telemetry Sidecar" ,
37+ zap .String ("version" , version ),
38+ zap .String ("configPath" , * configPath ),
39+ zap .String ("logLevel" , * logLevel ))
2640
27- // Create telemetry sidecar service
41+ // Create telemetry sidecar service (using the one from sidecar.go)
2842 sidecar := NewTelemetrySidecar (* configPath )
2943
3044 // Setup graceful shutdown context
@@ -37,15 +51,17 @@ func main() {
3751
3852 go func () {
3953 sig := <- sigCh
40- logger .Printf ("Received shutdown signal %v, initiating graceful shutdown" , sig )
54+ zapLogger .Info ("Received shutdown signal, initiating graceful shutdown" ,
55+ zap .String ("signal" , sig .String ()))
4156 cancel ()
4257 }()
4358
44- // Run the telemetry sidecar
59+ // Run the telemetry sidecar (using the Run method from sidecar.go)
4560 if err := sidecar .Run (ctx ); err != nil {
46- logger .Errorf ("Azure CNI Telemetry Sidecar failed: %v" , err )
61+ zapLogger .Error ("Azure CNI Telemetry Sidecar failed" ,
62+ zap .Error (err ))
4763 os .Exit (1 )
4864 }
4965
50- logger . Printf ("Azure CNI Telemetry Sidecar stopped gracefully" )
66+ zapLogger . Info ("Azure CNI Telemetry Sidecar stopped gracefully" )
5167}
0 commit comments