summaryrefslogtreecommitdiff
path: root/cmd/util/debug.go
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-09-29 23:37:16 +0300
committerGitHub <[email protected]>2018-09-29 23:37:16 +0300
commit6122fca108c20984732c969fb1ba53cce5b3c44a (patch)
tree40835f46a5c208ea2546b76e3bd9fa05429b405a /cmd/util/debug.go
parentabe62c0675f839586312cff1c83d6a4cb31dd9d5 (diff)
parenta04b5b33eb30944007973067ec07e9c4a2c464ab (diff)
Merge pull request #39 from spiral/feature/1.3.0v1.2.3
Feature/1.3.0
Diffstat (limited to 'cmd/util/debug.go')
-rw-r--r--cmd/util/debug.go57
1 files changed, 57 insertions, 0 deletions
diff --git a/cmd/util/debug.go b/cmd/util/debug.go
new file mode 100644
index 00000000..7be258ec
--- /dev/null
+++ b/cmd/util/debug.go
@@ -0,0 +1,57 @@
+package util
+
+import (
+ "github.com/sirupsen/logrus"
+ "github.com/spiral/roadrunner"
+ "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</red>",
+ *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:
+ logger.Warning(Sprintf(
+ "<yellow>%s</reset>",
+ strings.Trim(string(ctx.([]byte)), "\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
+ }
+
+ return false
+}