mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
route logging improvement: group by methods
Former-commit-id: ad884991433a244dc76bdad7314d98a5c204dac6
This commit is contained in:
parent
66e641513c
commit
346ca2a219
|
@ -32,7 +32,7 @@ func main() {
|
|||
func newApp() *iris.Application {
|
||||
app := iris.New()
|
||||
// app.Configure(iris.WithLowercaseRouting) // OPTIONAL.
|
||||
app.Logger().SetLevel("debug").SetTimeFormat("")
|
||||
app.Logger().SetLevel("debug")
|
||||
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
ctx.HTML("<h1>Index Page</h1>")
|
||||
|
|
|
@ -93,6 +93,8 @@ func registerSubdomains(app *iris.Application) {
|
|||
|
||||
func newApp() *iris.Application {
|
||||
app := iris.New()
|
||||
app.Logger().SetLevel("debug")
|
||||
|
||||
registerErrors(app)
|
||||
registerGamesRoutes(app)
|
||||
registerSubdomains(app)
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.Logger().SetLevel("debug").SetTimeFormat("")
|
||||
app.Logger().SetLevel("debug")
|
||||
|
||||
// GET: http://localhost:8080
|
||||
app.Get("/", info)
|
||||
|
|
|
@ -26,13 +26,13 @@ const MethodNone = "NONE"
|
|||
// "PATCH", "OPTIONS", "TRACE".
|
||||
var AllMethods = []string{
|
||||
http.MethodGet,
|
||||
http.MethodPost,
|
||||
http.MethodPut,
|
||||
http.MethodDelete,
|
||||
http.MethodConnect,
|
||||
http.MethodHead,
|
||||
http.MethodPatch,
|
||||
http.MethodPut,
|
||||
http.MethodPost,
|
||||
http.MethodDelete,
|
||||
http.MethodOptions,
|
||||
http.MethodConnect,
|
||||
http.MethodTrace,
|
||||
}
|
||||
|
||||
|
|
|
@ -153,8 +153,33 @@ func (h *routerHandler) Build(provider RoutesProvider) error {
|
|||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
golog.Debugf(r.Trace()) // keep log different parameter types in the same path as different routes.
|
||||
if golog.Default.Level == golog.DebugLevel {
|
||||
// group routes by method and print them without the [DBUG] and time info,
|
||||
// the route logs are colorful.
|
||||
// Note: don't use map, we need to keep registered order, use
|
||||
// different slices for each method.
|
||||
collect := func(method string) (methodRoutes []*Route) {
|
||||
for _, r := range registeredRoutes {
|
||||
if r.Method == method {
|
||||
methodRoutes = append(methodRoutes, r)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
bckpTimeFormat := golog.Default.TimeFormat
|
||||
defer golog.SetTimeFormat(bckpTimeFormat)
|
||||
golog.SetTimeFormat("")
|
||||
|
||||
for _, method := range AllMethods {
|
||||
methodRoutes := collect(method)
|
||||
for _, r := range methodRoutes {
|
||||
golog.Println(r.Trace())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return errgroup.Check(rp)
|
||||
|
|
Loading…
Reference in New Issue
Block a user