-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathoption.go
48 lines (40 loc) · 1.04 KB
/
option.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package log
import (
"io"
"os"
"github.com/rs/zerolog"
)
// Options are options for the [LoggerFactory] implementations.
type Options struct {
ServiceName string
Level zerolog.Level
OutputWriter io.Writer
}
// DefaultLoggerOptions are the default options used in the [DefaultLoggerFactory].
func DefaultLoggerOptions() Options {
return Options{
ServiceName: "default",
Level: zerolog.InfoLevel,
OutputWriter: os.Stdout,
}
}
// LoggerOption are functional options for the [LoggerFactory] implementations.
type LoggerOption func(o *Options)
// WithServiceName is used to add automatically a service log field value.
func WithServiceName(n string) LoggerOption {
return func(o *Options) {
o.ServiceName = n
}
}
// WithLevel is used to specify the log level to use.
func WithLevel(l zerolog.Level) LoggerOption {
return func(o *Options) {
o.Level = l
}
}
// WithOutputWriter is used to specify the output writer to use.
func WithOutputWriter(w io.Writer) LoggerOption {
return func(o *Options) {
o.OutputWriter = w
}
}