Skip to content

Commit 960b567

Browse files
authored
Add v2 zap logger to cns apis (#4003)
* Add zap logger to cns apis * Trying with z.with()
1 parent 03bb0ca commit 960b567

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

cns/common/service.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
acn "github.com/Azure/azure-container-networking/common"
1111
"github.com/Azure/azure-container-networking/server/tls"
1212
"github.com/Azure/azure-container-networking/store"
13+
"go.uber.org/zap"
1314
)
1415

1516
// Service implements behavior common to all services.
@@ -20,6 +21,7 @@ type Service struct {
2021
ErrChan chan<- error
2122
Store store.KeyValueStore
2223
ChannelMode string
24+
Logger *zap.Logger
2325
}
2426

2527
// ServiceAPI defines base interface.
@@ -41,6 +43,7 @@ type ServiceConfig struct {
4143
Server server
4244
ChannelMode string
4345
TLSSettings tls.TlsSettings
46+
Logger *zap.Logger
4447
}
4548

4649
// server struct to store primaryInterfaceIP from VM, port where customer provides by -p and temporary flag EnableLocalServer
@@ -80,6 +83,7 @@ func (service *Service) Initialize(config *ServiceConfig) error {
8083
service.Store = config.Store
8184
service.Version = config.Version
8285
service.ChannelMode = config.ChannelMode
86+
service.Logger = config.Logger
8387

8488
logger.Debugf("[Azure CNS] nitialized service: %+v with config: %+v.", service, config)
8589

cns/service/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ func main() {
646646
}
647647
host, _ := os.Hostname()
648648
z = z.With(zap.String("hostname", host), zap.String("version", version), zap.String("kubernetes_apiserver", os.Getenv("KUBERNETES_SERVICE_HOST")))
649+
config.Logger = z.With(zap.String("module", "cns service"))
649650
// Set the v2 logger to the global logger if v2 logger enabled.
650651
if cnsconfig.EnableLoggerV2 {
651652
logger.Printf("hotswapping logger v2") //nolint:staticcheck // ignore new deprecation

0 commit comments

Comments
 (0)