First pass

Signed-off-by: Itxaka <itxaka@kairos.io>
This commit is contained in:
Itxaka
2023-08-11 11:41:28 +02:00
parent f6ec86180b
commit b0c740c961
6 changed files with 224 additions and 48 deletions

34
logger/options.go Normal file
View File

@@ -0,0 +1,34 @@
package logger
import (
"github.com/rs/zerolog"
)
type LogOption func(a *KairosLog)
func WithLevel(level Level) func(k *KairosLog) {
return func(k *KairosLog) {
k.SetLevel(level)
}
}
// WithDebugFunction allows to pass a function that will set the logger to debug if the function returns true
// This is done so logger consumers can implement easily the check for debug, be it a file, a flag in cmd or an
// environment variable check
func WithDebugFunction(f func() bool) func(k *KairosLog) {
return func(k *KairosLog) {
if f() {
k.SetLevel(DebugLevel)
}
}
}
// WithStringContext overrides the default context of the existing logger to provide extra info in the log
func WithStringContext(key, value string) func(k *KairosLog) {
return func(k *KairosLog) {
k.Logger.UpdateContext(func(c zerolog.Context) zerolog.Context {
c.Str(key, value)
return c
})
}
}