summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-05-14 10:55:52 +0800
committertechknowlogick <techknowlogick@gitea.io>2019-05-13 22:55:52 -0400
commit61238407453072f015cc747224468fca5a08bd76 (patch)
tree597815fca75ddbf49402de67ccb873f3bb972cb4 /routers
parent3957b40021a7e017fc118a72fb5de38034427f00 (diff)
downloadgitea-61238407453072f015cc747224468fca5a08bd76.tar.gz
gitea-61238407453072f015cc747224468fca5a08bd76.zip
Remove macaron dependent on modules/log (#6933)
Diffstat (limited to 'routers')
-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()