Skip to content

Commit

Permalink
cni: use default logger with timestamps.
Browse files Browse the repository at this point in the history
Unlike runtime agent/operator logs, CNI logs are just written to disk so we have no way to attach timestamps to them.
This makes it harder to debug CNI issues as we have no way to correlate when things happened between Agent logs and CNI events.

This switches CNI to use the same default logger, except with timestamps enabled.

Signed-off-by: Tom Hadlaw <tom.hadlaw@isovalent.com>
  • Loading branch information
tommyp1ckles committed Mar 2, 2024
1 parent d697a14 commit b2fe069
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions pkg/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,21 @@ const (
FormatOpt = "format"

LogFormatText LogFormat = "text"
LogFormatTextTimestamp LogFormat = "text-ts"
LogFormatJSON LogFormat = "json"
LogFormatJSONTimestamp LogFormat = "json-ts"

// DefaultLogFormat is the string representation of the default logrus.Formatter
// we want to use (possible values: text or json)
DefaultLogFormat LogFormat = LogFormatText

// DefaultLogFormat is the string representation of the default logrus.Formatter
// including timestamps.
// We don't use this for general runtime logs since kubernetes log capture handles those.
// This is only used for applications such as CNI which is written to disk so we have no
// way to correlate with other logs.
DefaultLogFormatTimestamp LogFormat = LogFormatTextTimestamp

// DefaultLogLevel is the default log level we want to use for our logrus.Formatter
DefaultLogLevel logrus.Level = logrus.InfoLevel
)
Expand Down Expand Up @@ -202,6 +210,11 @@ func GetFormatter(format LogFormat) logrus.Formatter {
DisableTimestamp: true,
DisableColors: true,
}
case LogFormatTextTimestamp:
return &logrus.TextFormatter{
DisableTimestamp: false,
DisableColors: true,
}
case LogFormatJSON:
return &logrus.JSONFormatter{
DisableTimestamp: true,
Expand Down
2 changes: 1 addition & 1 deletion plugins/cilium-cni/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func prepareIP(ipAddr string, state *CmdState, mtu int) (*cniTypesV1.IPConfig, [
func setupLogging(n *types.NetConf) error {
f := n.LogFormat
if f == "" {
f = string(logging.DefaultLogFormat)
f = string(logging.DefaultLogFormatTimestamp)
}
logOptions := logging.LogOptions{
logging.FormatOpt: f,
Expand Down

0 comments on commit b2fe069

Please sign in to comment.