diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2022-01-20 19:41:25 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-20 19:41:25 +0800 |
commit | 5bf8d5445e3e3ec6b2be156654dcb233d78a570e (patch) | |
tree | 9a426fd03b619947b88931465c1a645540b94bfb /routers/install | |
parent | bbd30787d3d33fe66896c7e758e6922be459e252 (diff) | |
download | gitea-5bf8d5445e3e3ec6b2be156654dcb233d78a570e.tar.gz gitea-5bf8d5445e3e3ec6b2be156654dcb233d78a570e.zip |
Refactor Router Logger (#17308)
Make router logger more friendly, show the related function name/file/line.
[BREAKING]
This PR substantially changes the logging format of the router logger. If you use this logging for monitoring e.g. fail2ban you will need to update this to match the new format.
Diffstat (limited to 'routers/install')
-rw-r--r-- | routers/install/routes.go | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/routers/install/routes.go b/routers/install/routes.go index ad0003a9e8..d7d8527cf5 100644 --- a/routers/install/routes.go +++ b/routers/install/routes.go @@ -38,8 +38,8 @@ func installRecovery() func(next http.Handler) http.Handler { // should not panic any more. defer func() { if err := recover(); err != nil { - combinedErr := fmt.Sprintf("PANIC: %v\n%s", err, string(log.Stack(2))) - log.Error(combinedErr) + combinedErr := fmt.Sprintf("PANIC: %v\n%s", err, log.Stack(2)) + log.Error("%s", combinedErr) if setting.IsProd { http.Error(w, http.StatusText(500), 500) } else { @@ -49,8 +49,8 @@ func installRecovery() func(next http.Handler) http.Handler { }() if err := recover(); err != nil { - combinedErr := fmt.Sprintf("PANIC: %v\n%s", err, string(log.Stack(2))) - log.Error("%v", combinedErr) + combinedErr := fmt.Sprintf("PANIC: %v\n%s", err, log.Stack(2)) + log.Error("%s", combinedErr) lc := middleware.Locale(w, req) var store = dataStore{ @@ -85,10 +85,10 @@ func Routes() *web.Route { r.Use(middle) } - r.Use(public.AssetsHandler(&public.Options{ + r.Use(web.WrapWithPrefix(public.AssetsURLPathPrefix, public.AssetsHandlerFunc(&public.Options{ Directory: path.Join(setting.StaticRootPath, "public"), - Prefix: "/assets", - })) + Prefix: public.AssetsURLPathPrefix, + }), "InstallAssetsHandler")) r.Use(session.Sessioner(session.Options{ Provider: setting.SessionConfig.Provider, @@ -106,8 +106,11 @@ func Routes() *web.Route { r.Use(Init) r.Get("/", Install) r.Post("/", web.Bind(forms.InstallForm{}), SubmitInstall) - r.NotFound(func(w http.ResponseWriter, req *http.Request) { - http.Redirect(w, req, setting.AppURL, http.StatusFound) - }) + + r.NotFound(web.Wrap(installNotFound)) return r } + +func installNotFound(w http.ResponseWriter, req *http.Request) { + http.Redirect(w, req, setting.AppURL, http.StatusFound) +} |