-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
68 lines (54 loc) · 1.23 KB
/
options.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package glog
import (
"log/slog"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/log"
)
// Option provide a function to set configuration
type Option func(*config) error;
// WithLevel sets the log level for the logger.
func WithLevel(level slog.Level) Option {
return func(cfg *config) error {
cfg.options.Level = level;
return nil
}
}
// WithFormat sets the log format for the logger.
func WithFormat(format LogFormat) Option {
return func(cfg *config) error {
cfg.formatter = format;
return nil
}
}
func WithTimeStamp() Option {
return func(cfg *config) error {
cfg.withtimeStamp = true;
return nil
}
}
func WithReportCaller() Option {
return func(cfg *config) error {
cfg.reportCaller = true;
return nil
}
}
func WithStyle(styleOpts ...Style) Option {
return func(cfg *config) error {
styles, err := newStyle(styleOpts...)
if err != nil {
return err
}
cfg.styles = styles;
return nil
}
}
func WithErrorStyle() Style {
return func(sc *styleConfig) error {
sc.level[log.ErrorLevel] = lipgloss.NewStyle().
SetString("ERR ").
Padding(0, 1, 0).
Background(lipgloss.Color("204")).
Foreground(lipgloss.Color("0"))
return nil
}
}