1
0
mirror of https://github.com/MontFerret/ferret.git synced 2024-12-16 11:37:36 +02:00
ferret/pkg/runtime/logging/logger.go
Tim Voronov 2997a9b264
Bugfix/logging (#346)
* Fixed inability to pass custom ID to th runtime logger

* Removed UUID module

* Removed redundant check
2019-08-02 23:28:25 -04:00

47 lines
660 B
Go

package logging
import (
"context"
"io"
"github.com/rs/zerolog"
)
type (
Level uint8
Options struct {
Writer io.Writer
Level Level
Fields map[string]interface{}
}
)
const (
DebugLevel Level = iota
InfoLevel
WarnLevel
ErrorLevel
FatalLevel
PanicLevel
NoLevel
Disabled
)
func WithContext(ctx context.Context, opts Options) context.Context {
c := zerolog.New(opts.Writer).With().Timestamp()
for k, v := range opts.Fields {
c = c.Interface(k, v)
}
logger := c.Logger()
logger.Level(zerolog.Level(opts.Level))
return logger.WithContext(ctx)
}
func FromContext(ctx context.Context) *zerolog.Logger {
return zerolog.Ctx(ctx)
}