Files
wehub-resource-sync e071084ebe
govulncheck / govulncheck (push) Waiting to run
Harness (E2E) / Harnesses (mock LLM) (push) Waiting to run
Harness (E2E) / Provider harnesses (live LLM conformance) (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Run Tests / Unit Tests (push) Waiting to run
Run Tests / Etcd Integration Tests (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 12:40:33 +08:00

59 lines
1.2 KiB
Go

package logger
import (
"context"
"io"
)
type Option func(*Options)
type Options struct {
// It's common to set this to a file, or leave it default which is `os.Stderr`
Out io.Writer
// Alternative options
Context context.Context
// fields to always be logged
Fields map[string]interface{}
// Caller skip frame count for file:line info
CallerSkipCount int
// The logging level the logger should log at. default is `InfoLevel`
Level Level
}
// WithFields set default fields for the logger.
func WithFields(fields map[string]interface{}) Option {
return func(args *Options) {
args.Fields = fields
}
}
// WithLevel set default level for the logger.
func WithLevel(level Level) Option {
return func(args *Options) {
args.Level = level
}
}
// WithOutput set default output writer for the logger.
func WithOutput(out io.Writer) Option {
return func(args *Options) {
args.Out = out
}
}
// WithCallerSkipCount set frame count to skip.
func WithCallerSkipCount(c int) Option {
return func(args *Options) {
args.CallerSkipCount = c
}
}
func SetOption(k, v interface{}) Option {
return func(o *Options) {
if o.Context == nil {
o.Context = context.Background()
}
o.Context = context.WithValue(o.Context, k, v)
}
}