-
Notifications
You must be signed in to change notification settings - Fork 327
/
log_handler.go
68 lines (56 loc) · 1.73 KB
/
log_handler.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 automation
import (
"context"
"github.com/cortezaproject/corteza/server/pkg/logger"
"go.uber.org/zap"
)
type (
logHandler struct {
reg logHandlerRegistry
logger *zap.Logger
}
)
func zapFields(fields map[string]string) []zap.Field {
ff := make([]zap.Field, 0, len(fields))
for k, v := range fields {
ff = append(ff, zap.String(k, v))
}
return ff
}
func LogHandler(reg logHandlerRegistry) *logHandler {
h := &logHandler{
reg: reg,
// this is a temporary solution how to get to the logging facility
// without being dependent on workflow logging settings
//
// there are still general logging settings that have a final say what is logged and what not
//
// With LOG_DEBUG=true you'll see all log levels from these functions.
// With debug logging disabled and LOG_LEVEL set on error, warn, info or debug, you'll filter out
// logging by verbosity:
// error will show
// and with LOG_LEVEL=error on you'll just see logged errors
// while LOG_LEVEL=info will show info, warn and error but ignore debug.
logger: logger.Default().
Named("workflow").
WithOptions(zap.WithCaller(false)),
}
h.register()
return h
}
func (h logHandler) debug(_ context.Context, args *logDebugArgs) (err error) {
h.logger.Debug(args.Message, zapFields(args.Fields)...)
return nil
}
func (h logHandler) info(_ context.Context, args *logInfoArgs) (err error) {
h.logger.Info(args.Message, zapFields(args.Fields)...)
return nil
}
func (h logHandler) warn(_ context.Context, args *logWarnArgs) (err error) {
h.logger.Warn(args.Message, zapFields(args.Fields)...)
return nil
}
func (h logHandler) error(_ context.Context, args *logErrorArgs) (err error) {
h.logger.Error(args.Message, zapFields(args.Fields)...)
return nil
}