...
1 package clog
2
3 import (
4 "io"
5 "os"
6 )
7
8 type Option func(*options)
9
10
11
12 func To(dest io.Writer) Option {
13 return func(o *options) {
14 o.dest = dest
15 }
16 }
17
18
19 func WithLevel(lvl int) Option {
20 return func(o *options) {
21 o.lvl = lvl
22 }
23 }
24
25
26 func WithCaller(c MessageClass) Option {
27 return func(o *options) {
28 o.logCaller = c
29 }
30 }
31
32
33
34 type options struct {
35 dest io.Writer
36 lvl int
37 logCaller MessageClass
38 }
39
40 func makeOptions(opts ...Option) options {
41 o := options{dest: os.Stderr, logCaller: Error}
42 for _, opt := range opts {
43 opt(&o)
44 }
45
46 return o
47 }
48
View as plain text