mirror of
https://github.com/kataras/iris.git
synced 2026-01-08 12:31:58 +00:00
route logging improvement: group by methods
Former-commit-id: ad884991433a244dc76bdad7314d98a5c204dac6
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user