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
90
91
92
93
94
95
96
97
98
99
100
101
|
package util
import (
"github.com/sirupsen/logrus"
"github.com/spiral/roadrunner"
"github.com/spiral/roadrunner/service/watcher"
"strings"
)
// LogEvent outputs rr event into given logger and return false if event was not handled.
func LogEvent(logger *logrus.Logger, event int, ctx interface{}) bool {
switch event {
case roadrunner.EventWorkerKill:
w := ctx.(*roadrunner.Worker)
logger.Warning(Sprintf(
"<white+hb>worker.%v</reset> <yellow>killed</reset>",
*w.Pid,
))
return true
case roadrunner.EventWorkerError:
err := ctx.(roadrunner.WorkerError)
logger.Error(Sprintf(
"<white+hb>worker.%v</reset> <red>%s</reset>",
*err.Worker.Pid,
err.Caused,
))
return true
}
// outputs
switch event {
case roadrunner.EventStderrOutput:
for _, line := range strings.Split(string(ctx.([]byte)), "\n") {
if line == "" {
continue
}
logger.Warning(strings.Trim(line, "\r\n"))
}
return true
}
// rr server events
switch event {
case roadrunner.EventServerFailure:
logger.Error(Sprintf("<red>server is dead</reset>"))
return true
}
// pool events
switch event {
case roadrunner.EventPoolConstruct:
logger.Debug(Sprintf("<cyan>new worker pool</reset>"))
return true
case roadrunner.EventPoolError:
logger.Error(Sprintf("<red>%s</reset>", ctx))
return true
}
// watchers
switch event {
case watcher.EventMaxTTL:
w := ctx.(roadrunner.WorkerError)
logger.Debug(Sprintf(
"<white+hb>worker.%v</reset> <yellow>%s</reset>",
*w.Worker.Pid,
w.Caused,
))
return true
case watcher.EventMaxIdleTTL:
w := ctx.(roadrunner.WorkerError)
logger.Debug(Sprintf(
"<white+hb>worker.%v</reset> <yellow>%s</reset>",
*w.Worker.Pid,
w.Caused,
))
return true
case watcher.EventMaxMemory:
w := ctx.(roadrunner.WorkerError)
logger.Error(Sprintf(
"<white+hb>worker.%v</reset> <red>%s</reset>",
*w.Worker.Pid,
w.Caused,
))
return true
case watcher.EventMaxExecTTL:
w := ctx.(roadrunner.WorkerError)
logger.Error(Sprintf(
"<white+hb>worker.%v</reset> <red>%s</reset>",
*w.Worker.Pid,
w.Caused,
))
return true
}
return false
}
|