add TraceRoute feature on request logger

This commit is contained in:
Gerasimos (Makis) Maropoulos 2020-08-18 19:33:07 +03:00
parent e98fd21c83
commit 35ab1de212
No known key found for this signature in database
GPG Key ID: 5DBE766BD26A54E7
4 changed files with 16 additions and 1 deletions

View File

@ -359,6 +359,10 @@ Response:
Other Improvements:
- New `TraceRoute bool` on [request logger](https://github.com/kataras/iris/tree/master/middleware/logger) middleware. Displays information about the executed route, screenshot:
![logger middleware: TraceRoute screenshot](https://iris-go.com/images/github/logger-trace-route.png)
- Implement feature request [Log when I18n Translation Fails?](https://github.com/kataras/iris/issues/1593) by using the new `Application.I18n.DefaultMessageFunc` field **before** `I18n.Load`. [Example of usage](https://github.com/kataras/iris/blob/master/_examples/i18n/main.go#L28-L50).
- Fix [#1594](https://github.com/kataras/iris/issues/1594) and add a new `PathAfterHandler` which can be set to true to enable the old behavior (not recommended though).

View File

@ -19,6 +19,8 @@ func main() {
Path: true,
// Query appends the url query to the Path.
Query: true,
// Shows information about the executed route.
TraceRoute: true,
// Columns: true,

View File

@ -37,12 +37,16 @@ type Config struct {
//
// Defaults to false.
PathAfterHandler bool
// Query will append the URL Query to the Path.
// Path should be true too.
//
// Defaults to false.
Query bool
// TraceRoute displays the debug
// information about the current route executed.
//
// Defaults to false.
TraceRoute bool
// Columns will display the logs as a formatted columns-rows text (bool).
// If custom `LogFunc` has been provided then this field is useless and users should
@ -100,6 +104,7 @@ func DefaultConfig() Config {
Path: true,
PathAfterHandler: false,
Query: false,
TraceRoute: false,
Columns: false,
LogFunc: nil,
LogFuncCtx: nil,

View File

@ -139,6 +139,10 @@ func (l *requestLoggerMiddleware) ServeHTTP(ctx *context.Context) {
} else {
ctx.Application().Logger().Info(line)
}
if l.config.TraceRoute && ctx.GetCurrentRoute() != nil /* it is nil on unhandled error codes */ {
ctx.GetCurrentRoute().Trace(ctx.Application().Logger().Printer)
}
}
// Columnize formats the given arguments as columns and returns the formatted output,