diff --git a/HISTORY.md b/HISTORY.md index 2bec68fb..27b0b46c 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -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). diff --git a/_examples/logging/request-logger/main.go b/_examples/logging/request-logger/main.go index 1e89d833..00d06e13 100644 --- a/_examples/logging/request-logger/main.go +++ b/_examples/logging/request-logger/main.go @@ -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, diff --git a/middleware/logger/config.go b/middleware/logger/config.go index 6b8d2901..54d277ce 100644 --- a/middleware/logger/config.go +++ b/middleware/logger/config.go @@ -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, diff --git a/middleware/logger/logger.go b/middleware/logger/logger.go index 4469bfd4..56dd221f 100644 --- a/middleware/logger/logger.go +++ b/middleware/logger/logger.go @@ -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,