summaryrefslogtreecommitdiffstats
path: root/routers/routes/routes.go
diff options
context:
space:
mode:
Diffstat (limited to 'routers/routes/routes.go')
-rw-r--r--routers/routes/routes.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/routers/routes/routes.go b/routers/routes/routes.go
index 938afcab79..5a5fc518b9 100644
--- a/routers/routes/routes.go
+++ b/routers/routes/routes.go
@@ -94,6 +94,21 @@ func setupAccessLogger(m *macaron.Macaron) {
})
}
+// RouterHandler is a macaron handler that will log the routing to the default gitea log
+func RouterHandler(level log.Level) func(ctx *macaron.Context) {
+ return func(ctx *macaron.Context) {
+ start := time.Now()
+
+ log.GetLogger("router").Log(0, level, "Started %s %s for %s", log.ColoredMethod(ctx.Req.Method), ctx.Req.RequestURI, ctx.RemoteAddr())
+
+ rw := ctx.Resp.(macaron.ResponseWriter)
+ ctx.Next()
+
+ status := rw.Status()
+ log.GetLogger("router").Log(0, level, "Completed %s %s %v %s in %v", log.ColoredMethod(ctx.Req.Method), ctx.Req.RequestURI, log.ColoredStatus(status), log.ColoredStatus(status, http.StatusText(rw.Status())), log.ColoredTime(time.Since(start)))
+ }
+}
+
// NewMacaron initializes Macaron instance.
func NewMacaron() *macaron.Macaron {
gob.Register(&u2f.Challenge{})
@@ -102,7 +117,9 @@ func NewMacaron() *macaron.Macaron {
loggerAsWriter := log.NewLoggerAsWriter("INFO", log.GetLogger("macaron"))
m = macaron.NewWithLogger(loggerAsWriter)
if !setting.DisableRouterLog && setting.RouterLogLevel != log.NONE {
- log.SetupRouterLogger(m, setting.RouterLogLevel)
+ if log.GetLogger("router").GetLevel() <= setting.RouterLogLevel {
+ m.Use(RouterHandler(setting.RouterLogLevel))
+ }
}
} else {
m = macaron.New()