Skip to content

Use NGF logger in client-go library #2618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/gateway/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"go.uber.org/zap"
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/log"
ctlrZap "sigs.k8s.io/controller-runtime/pkg/log/zap"

Expand Down Expand Up @@ -125,6 +126,8 @@
atom := zap.NewAtomicLevel()

logger := ctlrZap.New(ctlrZap.Level(atom))
klog.SetLogger(logger)

Check warning on line 129 in cmd/gateway/commands.go

View check run for this annotation

Codecov / codecov/patch

cmd/gateway/commands.go#L129

Added line #L129 was not covered by tests

commit, date, dirty := getBuildInfo()
logger.Info(
"Starting NGINX Gateway Fabric in static mode",
Expand Down
1 change: 1 addition & 0 deletions docs/developer/logging-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@ There are two critical libraries for NGF that log:
of that project.
- [client-go](https://github.com/kubernetes/client-go).
- It uses [klog](https://github.com/kubernetes/klog) for logging.
- We inject the above logger into klog to ensure it uses the same formatting.
- Most of the logging is done at increased klog-specific
verbosity. However, errors are logged at the default verbosity like
in [this line](https://github.com/kubernetes/client-go/blob/c5b1c13ccbedeb03c00ba162ef27566b0dfb512d/tools/record/event.go#L240).
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require (
k8s.io/apiextensions-apiserver v0.31.1
k8s.io/apimachinery v0.31.1
k8s.io/client-go v0.31.1
k8s.io/klog/v2 v2.130.1
sigs.k8s.io/controller-runtime v0.19.0
sigs.k8s.io/gateway-api v1.1.0
)
Expand Down Expand Up @@ -89,7 +90,6 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240423202451-8948a665c108 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
Expand Down
Loading