0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-30 22:34:13 -05:00

Fix logger race condition (#817)

Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com>
This commit is contained in:
LaurentiuNiculae 2022-09-26 18:18:28 +03:00 committed by GitHub
parent 6b1d8925c2
commit b9d878e013
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,7 @@ import (
"runtime"
"strconv"
"strings"
"sync"
"time"
"github.com/rs/zerolog"
@ -12,6 +13,9 @@ import (
const defaultPerms = 0o0600
// nolint:gochecknoglobals
var loggerSetTimeFormat sync.Once
// Logger extends zerolog's Logger.
type Logger struct {
zerolog.Logger
@ -22,7 +26,9 @@ func (l Logger) Println(v ...interface{}) {
}
func NewLogger(level, output string) Logger {
zerolog.TimeFieldFormat = time.RFC3339Nano
loggerSetTimeFormat.Do(func() {
zerolog.TimeFieldFormat = time.RFC3339Nano
})
lvl, err := zerolog.ParseLevel(level)
if err != nil {
@ -47,7 +53,9 @@ func NewLogger(level, output string) Logger {
}
func NewAuditLogger(level, audit string) *Logger {
zerolog.TimeFieldFormat = time.RFC3339Nano
loggerSetTimeFormat.Do(func() {
zerolog.TimeFieldFormat = time.RFC3339Nano
})
lvl, err := zerolog.ParseLevel(level)
if err != nil {