-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.go
51 lines (45 loc) · 1.16 KB
/
log.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
package cron
import (
"context"
"fmt"
"log"
"syscall"
"github.com/wfusion/gofusion/config"
)
func (a *asynqRouter) debug(ctx context.Context, msg string, args ...any) {
msg = a.format(msg)
if a.logger == nil {
log.Printf(msg, args...)
} else {
logArgs := make([]any, 0, len(args)+2)
logArgs = append(logArgs, ctx, msg)
logArgs = append(logArgs, args...)
a.logger.Debug(logArgs...)
}
}
func (a *asynqRouter) info(ctx context.Context, msg string, args ...any) {
msg = a.format(msg)
if a.logger == nil {
log.Printf(msg, args...)
} else {
logArgs := make([]any, 0, len(args)+2)
logArgs = append(logArgs, ctx, msg)
logArgs = append(logArgs, args...)
a.logger.Info(logArgs...)
}
}
func (a *asynqRouter) warn(ctx context.Context, msg string, args ...any) {
msg = a.format(msg)
if a.logger == nil {
log.Printf(msg, args...)
} else {
logArgs := make([]any, 0, len(args)+2)
logArgs = append(logArgs, ctx, msg)
logArgs = append(logArgs, args...)
a.logger.Warn(logArgs...)
}
}
func (a *asynqRouter) format(src string) (dst string) {
return fmt.Sprintf("%v [Gofusion] %s %s asynq(%s) %s",
syscall.Getpid(), config.ComponentCron, a.n, a.id, src)
}