Skip to content
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

Use ISO8601 timestamp format for zap log messages #843

Merged
merged 2 commits into from
Oct 12, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ spec:
name: kubernetes-nmstate-operator
spec:
containers:
- args:
- --v=production
command:
- command:
- manager
env:
- name: WATCH_NAMESPACE
Expand Down
6 changes: 0 additions & 6 deletions deploy/handler/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ spec:
priorityClassName: system-cluster-critical
containers:
- name: nmstate-webhook
args:
- --v=production
# Replace this with the built image name
image: {{ .HandlerImage }}
imagePullPolicy: {{ .HandlerPullPolicy }}
Expand Down Expand Up @@ -115,8 +113,6 @@ spec:
priorityClassName: system-cluster-critical
containers:
- name: nmstate-cert-manager
args:
- --v=production
# Replace this with the built image name
image: {{ .HandlerImage }}
imagePullPolicy: {{ .HandlerPullPolicy }}
Expand Down Expand Up @@ -209,8 +205,6 @@ spec:
priorityClassName: system-node-critical
containers:
- name: nmstate-handler
args:
- --v=production
# Replace this with the built image name
image: {{ .HandlerImage }}
imagePullPolicy: {{ .HandlerPullPolicy }}
Expand Down
2 changes: 0 additions & 2 deletions deploy/operator/operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ spec:
effect: NoSchedule
containers:
- name: nmstate-operator
args:
- --v=production
# Replace this with the built image name
image: {{ .OperatorImage }}
imagePullPolicy: {{ .OperatorPullPolicy }}
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ require (
github.com/phoracek/networkmanager-go v0.1.0
github.com/pkg/errors v0.9.1
github.com/qinqon/kube-admission-webhook v0.17.0
github.com/spf13/pflag v1.0.5
github.com/tidwall/gjson v1.8.0
github.com/tidwall/sjson v1.1.7
go.uber.org/zap v1.17.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.21.1
k8s.io/apimachinery v0.21.1
Expand Down
27 changes: 24 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"os"
"time"

"go.uber.org/zap/zapcore"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/fields"
"k8s.io/apimachinery/pkg/labels"
Expand All @@ -35,12 +36,14 @@ import (
"sigs.k8s.io/controller-runtime/pkg/cache"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log/zap"

// +kubebuilder:scaffold:imports

"github.com/gofrs/flock"
"github.com/kelseyhightower/envconfig"
"github.com/pkg/errors"
"github.com/qinqon/kube-admission-webhook/pkg/certificate"
"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/util/wait"

nmstateapi "github.com/nmstate/kubernetes-nmstate/api/shared"
Expand Down Expand Up @@ -73,11 +76,20 @@ func init() {
}

func main() {
opt := zap.Options{}
opt.BindFlags(flag.CommandLine)
var logType string
flag.StringVar(&logType, "v", "production", "Log type (debug/production).")
flag.Parse()
pflag.StringVar(&logType, "v", "production", "Log type (debug/production).")
pflag.CommandLine.MarkDeprecated("v", "please use the --zap-devel flag for debug logging instead")
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()

if logType == "debug" {
// workaround until --v flag got removed
flag.CommandLine.Set("zap-devel", "true")
}

ctrl.SetLogger(zap.New(zap.UseDevMode(logType != "production")))
setupLogger(opt)

// Lock only for handler, we can run old and new version of
// webhook without problems, policy status will be updated
Expand Down Expand Up @@ -252,6 +264,15 @@ func main() {
}
}

func setupLogger(opts zap.Options) {
opts.EncoderConfigOptions = append(opts.EncoderConfigOptions, func(ec *zapcore.EncoderConfig) {
ec.EncodeTime = zapcore.ISO8601TimeEncoder
})

logger := zap.New(zap.UseFlagOptions(&opts))
ctrl.SetLogger(logger)
}

// Start profiler on given port if ENABLE_PROFILER is True
func setProfiler() {
cfg := ProfilerConfig{}
Expand Down
2 changes: 2 additions & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ github.com/sirupsen/logrus
# github.com/spf13/cobra v1.1.3
github.com/spf13/cobra
# github.com/spf13/pflag v1.0.5
## explicit
github.com/spf13/pflag
# github.com/spiegel-im-spiegel/errs v1.0.2
github.com/spiegel-im-spiegel/errs
Expand Down Expand Up @@ -642,6 +643,7 @@ go.uber.org/atomic
# go.uber.org/multierr v1.6.0
go.uber.org/multierr
# go.uber.org/zap v1.17.0
## explicit
go.uber.org/zap
go.uber.org/zap/buffer
go.uber.org/zap/internal/bufferpool
Expand Down