TUN-3795: Use RFC-3339 style date format for logs, produce timestamp in UTC
This commit is contained in:
parent
7df3a1ab67
commit
0df4f7dd24
|
@ -7,6 +7,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/mattn/go-colorable"
|
"github.com/mattn/go-colorable"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
|
@ -30,8 +31,18 @@ const (
|
||||||
|
|
||||||
dirPermMode = 0744 // rwxr--r--
|
dirPermMode = 0744 // rwxr--r--
|
||||||
filePermMode = 0644 // rw-r--r--
|
filePermMode = 0644 // rw-r--r--
|
||||||
|
|
||||||
|
consoleTimeFormat = time.RFC3339
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
zerolog.TimestampFunc = utcNow
|
||||||
|
}
|
||||||
|
|
||||||
|
func utcNow() time.Time {
|
||||||
|
return time.Now().UTC()
|
||||||
|
}
|
||||||
|
|
||||||
func fallbackLogger(err error) *zerolog.Logger {
|
func fallbackLogger(err error) *zerolog.Logger {
|
||||||
failLog := fallbacklog.With().Logger()
|
failLog := fallbacklog.With().Logger()
|
||||||
fallbacklog.Error().Msgf("Falling back to a default logger due to logger setup failure: %s", err)
|
fallbacklog.Error().Msgf("Falling back to a default logger due to logger setup failure: %s", err)
|
||||||
|
@ -53,7 +64,6 @@ func (t resilientMultiWriter) Write(p []byte) (n int, err error) {
|
||||||
return len(p), nil
|
return len(p), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func newZerolog(loggerConfig *Config) *zerolog.Logger {
|
func newZerolog(loggerConfig *Config) *zerolog.Logger {
|
||||||
var writers []io.Writer
|
var writers []io.Writer
|
||||||
|
|
||||||
|
@ -143,6 +153,7 @@ func createConsoleLogger(config ConsoleConfig) io.Writer {
|
||||||
return zerolog.ConsoleWriter{
|
return zerolog.ConsoleWriter{
|
||||||
Out: colorable.NewColorable(consoleOut),
|
Out: colorable.NewColorable(consoleOut),
|
||||||
NoColor: config.noColor || !term.IsTerminal(int(consoleOut.Fd())),
|
NoColor: config.noColor || !term.IsTerminal(int(consoleOut.Fd())),
|
||||||
|
TimeFormat: consoleTimeFormat,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package origin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -145,3 +146,16 @@ func TestBackoffRetryForever(t *testing.T) {
|
||||||
t.Fatalf("backoff returned %v instead of 8 seconds on fifth retry", duration)
|
t.Fatalf("backoff returned %v instead of 8 seconds on fifth retry", duration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrint(t *testing.T) {
|
||||||
|
local := time.Now()
|
||||||
|
fmt.Printf("Local = %s\n", local)
|
||||||
|
fmt.Printf("Local (kitchen) = %s\n", local.Format(time.Kitchen))
|
||||||
|
fmt.Printf("Local (RFC3339) = %s\n", local.Format(time.RFC3339))
|
||||||
|
fmt.Println()
|
||||||
|
utc := local.UTC()
|
||||||
|
fmt.Printf("UTC = %s\n", utc)
|
||||||
|
fmt.Printf("UTC (kitchen) = %s\n", utc.Format(time.Kitchen))
|
||||||
|
fmt.Printf("UTC (RFC3339) = %s\n", utc.Format(time.RFC3339))
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue