Skip to content

Conversation

pjohnst5
Copy link
Contributor

@pjohnst5 pjohnst5 commented Sep 4, 2025

I see we now have a zap logger v2 for cns

In #4002. I am getting:
SA1019: logger.Printf is deprecated: The global logger is deprecated. Migrate to zap using the cns/logger/v2 package and pass the logger instead. (staticcheck)

So this PR is to introduce the zap v2 logger into CNS APIs, by plumbing it through the CNS service config

Thoughts?

This would make

logger.Printf("[Azure CNS] setEnvironment")

Into something like this:

service.Logger.Info("[Azure CNS] setEnvironment")

I understand we already have a way to make logger.Printf() to point to a v2 zap logger underneath:

if cnsconfig.EnableLoggerV2 {
logger.Printf("hotswapping logger v2") //nolint:staticcheck // ignore new deprecation
logger.Log = loggerv2.AsV1(z, c)
}

But this is more about when adding new APIs, and to avoid the linting errors

@Copilot Copilot AI review requested due to automatic review settings September 4, 2025 21:27
@pjohnst5 pjohnst5 requested a review from a team as a code owner September 4, 2025 21:27
@pjohnst5 pjohnst5 changed the title Add zap logger to cns apis Add v2 zap logger to cns apis Sep 4, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds zap logger v2 support to CNS APIs by plumbing the logger through the service configuration. The change addresses deprecation warnings for the global logger.Printf method by providing a structured logger instance to CNS services.

  • Adds Logger field to ServiceConfig and Service structs to carry the zap logger
  • Initializes the logger in the main service configuration
  • Sets up the logger during service initialization

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
cns/service/main.go Assigns the zap logger instance to the service config
cns/common/service.go Adds Logger field to ServiceConfig and Service structs and initializes it

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@pjohnst5 pjohnst5 requested a review from rbtr September 4, 2025 21:28
@pjohnst5
Copy link
Contributor Author

pjohnst5 commented Sep 4, 2025

/azp run Azure Container Networking PR

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Collaborator

@rbtr rbtr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if V2 Logger is not enabled? Maybe we need a V1asV2 shim for migration?

@pjohnst5
Copy link
Contributor Author

/azp run Azure Container Networking PR

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@paulyufan2 paulyufan2 added this pull request to the merge queue Sep 10, 2025
Merged via the queue into master with commit 960b567 Sep 11, 2025
15 of 16 checks passed
@paulyufan2 paulyufan2 deleted the pjohnst5/add-zap-logger-to-cns-apis branch September 11, 2025 00:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants