mirror of
https://github.com/kataras/iris.git
synced 2025-12-24 05:17:03 +00:00
Update to 8.0.4 | New: transfer a message to the request logger
Former-commit-id: 2bab3c9f28f7e9edd5d85e579349f70388af871d
This commit is contained in:
@@ -18,6 +18,11 @@ func main() {
|
||||
Method: true,
|
||||
// Path displays the request path
|
||||
Path: true,
|
||||
// Columns: true,
|
||||
|
||||
// if !empty then its contents derives from `ctx.Values().Get("logger_message")
|
||||
// will be added to the logs.
|
||||
MessageContextKey: "logger_message",
|
||||
})
|
||||
|
||||
app.Use(customLogger)
|
||||
@@ -40,6 +45,10 @@ func main() {
|
||||
*/
|
||||
// or catch all http errors:
|
||||
app.OnAnyErrorCode(customLogger, func(ctx context.Context) {
|
||||
// this should be added to the logs, at the end because of the `logger.Config#MessageContextKey`
|
||||
ctx.Values().Set("logger_message",
|
||||
"a dynamic message passed to the logs")
|
||||
|
||||
ctx.Writef("My Custom error page")
|
||||
})
|
||||
|
||||
|
||||
@@ -86,8 +86,8 @@ func newRequestLogger() (h context.Handler, close func() error) {
|
||||
return err
|
||||
}
|
||||
|
||||
c.LogFunc = func(now time.Time, latency time.Duration, status, ip, method, path string) {
|
||||
output := logger.Columnize(now.Format("2006/01/02 - 15:04:05"), latency, status, ip, method, path)
|
||||
c.LogFunc = func(now time.Time, latency time.Duration, status, ip, method, path string, message interface{}) {
|
||||
output := logger.Columnize(now.Format("2006/01/02 - 15:04:05"), latency, status, ip, method, path, message)
|
||||
logFile.Write([]byte(output))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user