Skip to content

Commit

Permalink
Disable file logger if running tests
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinguidee committed Sep 24, 2023
1 parent f80a2a3 commit b32db70
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions pkg/log/log.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
package log

import "github.com/vertex-center/vlog"
import (
"os"
"strings"

var Default = *vlog.New(
vlog.WithOutputStd(),
vlog.WithOutputFile("live/logs", vlog.LogFormatText),
vlog.WithOutputFile("live/logs", vlog.LogFormatJson),
"github.com/vertex-center/vlog"
)

var Default vlog.Logger

func init() {
if strings.HasSuffix(os.Args[0], ".test") {
Default = *vlog.New(
vlog.WithOutputStd(),
)
Default.Info("test logger initialized")
} else {
println("Using full logger")
Default = *vlog.New(
vlog.WithOutputStd(),
vlog.WithOutputFile("live/logs", vlog.LogFormatText),
vlog.WithOutputFile("live/logs", vlog.LogFormatJson),
)
Default.Info("full logger initialized")
}
}

func Debug(msg string, fields ...vlog.KeyValue) {
Default.Debug(msg, fields...)
}
Expand Down

0 comments on commit b32db70

Please sign in to comment.