-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.go
89 lines (83 loc) · 2.4 KB
/
logging.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package sprout
import (
"github.com/levelfourab/sprout-go/internal/logging"
"go.uber.org/zap"
)
// CreateLogger creates a logger with a name. This is provided as an
// alternative to defining loggers in your module with fx.Provide via
// sprout.Logger.
func CreateLogger(name ...string) *zap.Logger {
return logging.CreateLogger(zap.L(), name)
}
// Logger creates a function that can be used to create a logger with a name.
// Can be used with fx.Decorate or fx.Provide.
//
// It is mostly used when creating a module, to supply a logger with a name
// that is specific to the module.
//
// Example:
//
// var Module = fx.Module(
// "example",
// fx.Provide(sprout.Logger("name", "of", "logger"), fx.PRivate),
// fx.Invoke(func(logger *zap.Logger) {
// // ...
// }),
// )
func Logger(name ...string) any {
return logging.Logger(name...)
}
// SugaredLogger creates a function that can be used to create a sugared logger
// with a name. Can be used with fx.Decorate or fx.Provide.
//
// It is mostly used when creating a module, to supply a sugared logger with a
// name that is specific to the module.
//
// Example:
//
// var Module = fx.Module(
// "example",
// fx.Provide(sprout.SugaredLogger("name", "of", "logger"), fx.Private),
// fx.Invoke(func(logger *zap.SugaredLogger) {
// // ...
// }),
// )
func SugaredLogger(name ...string) any {
return logging.SugaredLogger(name...)
}
// LogrLogger creates a function that can be used to create a logr logger with
// a name. Can be used with fx.Decorate or fx.Provide.
//
// It is mostly used when creating a module, to supply a logr logger with a
// name that is specific to the module.
//
// Example:
//
// var Module = fx.Module(
// "example",
// fx.Provide(sprout.LogrLogger("name", "of", "logger"), fx.Private),
// fx.Invoke(func(logger logr.Logger) {
// // ...
// }),
// )
func LogrLogger(name ...string) any {
return logging.LogrLogger(name...)
}
// SlogLogger creates a function that can be used to create a log/slog logger
// with a name. Can be used with fx.Decorate or fx.Provide.
//
// It is mostly used when creating a module, to supply a log/slog logger to
// libraries that require it.
//
// Example:
//
// var Module = fx.Module(
// "example",
// fx.Provide(sprout.SlogLogger("name", "of", "logger"), fx.Private),
// fx.Invoke(func(logger *slog.Logger) {
// // ...
// }),
// )
func SlogLogger(name ...string) any {
return logging.SlogLogger(name...)
}