micro-logger-zerolog/options.go
Vasiliy Tolstov d3e8fb0415
Some checks failed
autoapprove / autoapprove (pull_request) Failing after 1m25s
automerge / automerge (pull_request) Failing after 3s
codeql / analyze (go) (pull_request) Failing after 3m9s
dependabot-automerge / automerge (pull_request) Has been skipped
prbuild / test (pull_request) Failing after 1m28s
prbuild / lint (pull_request) Failing after 2m37s
update for latest micro changes
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
2023-08-15 07:51:31 +03:00

74 lines
1.6 KiB
Go

package zerolog
import (
"github.com/rs/zerolog"
"go.unistack.org/micro/v4/logger"
"go.unistack.org/micro/v4/options"
)
type Options struct {
logger.Options
// Flag for whether to log caller info (off by default)
ReportCaller bool
// Use this logger as system wide default logger (off by default)
UseAsDefault bool
// zerolog hooks
Hooks []zerolog.Hook
// TimeFormat is one of time.RFC3339, time.RFC3339Nano, time.*
TimeFormat string
// Runtime mode. (Production by default)
Mode Mode
// Exit Function to call when FatalLevel log
ExitFunc func(int)
}
type reportCallerKey struct{}
func ReportCaller() options.Option {
return options.ContextOption(reportCallerKey{}, true)
}
type useAsDefaultKey struct{}
func UseAsDefault() options.Option {
return options.ContextOption(useAsDefaultKey{}, true)
}
type developmentModeKey struct{}
func WithDevelopmentMode() options.Option {
return options.ContextOption(developmentModeKey{}, true)
}
type productionModeKey struct{}
func WithProductionMode() options.Option {
return options.ContextOption(productionModeKey{}, true)
}
type timeFormatKey struct{}
func WithTimeFormat(timeFormat string) options.Option {
return options.ContextOption(timeFormatKey{}, timeFormat)
}
type hooksKey struct{}
func WithHooks(hooks []zerolog.Hook) options.Option {
return options.ContextOption(hooksKey{}, hooks)
}
type exitKey struct{}
func WithExitFunc(exit func(int)) options.Option {
return options.ContextOption(exitKey{}, exit)
}
type loggerKey struct{}
func WithLogger(l logger.Logger) options.Option {
return options.ContextOption(loggerKey{}, l)
}