summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorWolfy-J <[email protected]>2018-07-08 21:01:19 -0700
committerWolfy-J <[email protected]>2018-07-08 21:01:19 -0700
commita180d5e1128f735976497dff69c8c3a1061c42c7 (patch)
tree11540a1f3005f688f91125f80309afc7fec83b63 /cmd
parent89fe2046ce3b2c22188d731d00db4917fc77d834 (diff)
better debugging
Diffstat (limited to 'cmd')
-rw-r--r--cmd/rr/debug/debugger.go48
1 files changed, 35 insertions, 13 deletions
diff --git a/cmd/rr/debug/debugger.go b/cmd/rr/debug/debugger.go
index 533a5947..fdf3c1be 100644
--- a/cmd/rr/debug/debugger.go
+++ b/cmd/rr/debug/debugger.go
@@ -4,8 +4,10 @@ import (
"github.com/sirupsen/logrus"
"github.com/spiral/roadrunner"
"github.com/spiral/roadrunner/cmd/rr/utils"
- "github.com/spiral/roadrunner/service/http"
+ rrhttp "github.com/spiral/roadrunner/service/http"
"strings"
+ "fmt"
+ "net/http"
)
// Listener creates new debug listener.
@@ -20,21 +22,32 @@ type debugger struct{ logger *logrus.Logger }
func (s *debugger) listener(event int, ctx interface{}) {
// http events
switch event {
- case http.EventResponse:
- log := ctx.(*http.Event)
- s.logger.Info(utils.Sprintf("%s <white+hb>%s</reset> %s", statusColor(log.Status), log.Method, log.URI))
- case http.EventError:
- log := ctx.(*http.Event)
-
- if _, ok := log.Error.(roadrunner.JobError); ok {
- s.logger.Info(utils.Sprintf("%s <white+hb>%s</reset> %s", statusColor(log.Status), log.Method, log.URI))
+ case rrhttp.EventResponse:
+ e := ctx.(*rrhttp.ResponseEvent)
+ s.logger.Info(utils.Sprintf(
+ "<cyan+h>%s</reset> %s <white+hb>%s</reset> %s",
+ e.Request.RemoteAddr,
+ statusColor(e.Response.Status),
+ e.Request.Method,
+ e.Request.URI,
+ ))
+ case rrhttp.EventError:
+ e := ctx.(*rrhttp.ErrorEvent)
+
+ if _, ok := e.Error.(roadrunner.JobError); ok {
+ s.logger.Info(utils.Sprintf(
+ "%s <white+hb>%s</reset> %s",
+ statusColor(500),
+ e.Request.Method,
+ uri(e.Request),
+ ))
} else {
s.logger.Info(utils.Sprintf(
"%s <white+hb>%s</reset> %s <red>%s</reset>",
- statusColor(log.Status),
- log.Method,
- log.URI,
- log.Error,
+ statusColor(500),
+ e.Request.Method,
+ uri(e.Request),
+ e.Error,
))
}
}
@@ -93,3 +106,12 @@ func statusColor(status int) string {
return utils.Sprintf("<red>%v</reset>", status)
}
+
+// uri fetches full uri from request in a form of string (including https scheme if TLS connection is enabled).
+func uri(r *http.Request) string {
+ if r.TLS != nil {
+ return fmt.Sprintf("https://%s%s", r.Host, r.URL.String())
+ }
+
+ return fmt.Sprintf("http://%s%s", r.Host, r.URL.String())
+} \ No newline at end of file