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:
parent
6b1d8925c2
commit
b9d878e013
1 changed files with 10 additions and 2 deletions
|
@ -5,6 +5,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
|
@ -12,6 +13,9 @@ import (
|
||||||
|
|
||||||
const defaultPerms = 0o0600
|
const defaultPerms = 0o0600
|
||||||
|
|
||||||
|
// nolint:gochecknoglobals
|
||||||
|
var loggerSetTimeFormat sync.Once
|
||||||
|
|
||||||
// Logger extends zerolog's Logger.
|
// Logger extends zerolog's Logger.
|
||||||
type Logger struct {
|
type Logger struct {
|
||||||
zerolog.Logger
|
zerolog.Logger
|
||||||
|
@ -22,7 +26,9 @@ func (l Logger) Println(v ...interface{}) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLogger(level, output string) Logger {
|
func NewLogger(level, output string) Logger {
|
||||||
zerolog.TimeFieldFormat = time.RFC3339Nano
|
loggerSetTimeFormat.Do(func() {
|
||||||
|
zerolog.TimeFieldFormat = time.RFC3339Nano
|
||||||
|
})
|
||||||
|
|
||||||
lvl, err := zerolog.ParseLevel(level)
|
lvl, err := zerolog.ParseLevel(level)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -47,7 +53,9 @@ func NewLogger(level, output string) Logger {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAuditLogger(level, audit string) *Logger {
|
func NewAuditLogger(level, audit string) *Logger {
|
||||||
zerolog.TimeFieldFormat = time.RFC3339Nano
|
loggerSetTimeFormat.Do(func() {
|
||||||
|
zerolog.TimeFieldFormat = time.RFC3339Nano
|
||||||
|
})
|
||||||
|
|
||||||
lvl, err := zerolog.ParseLevel(level)
|
lvl, err := zerolog.ParseLevel(level)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue