mirror of
https://github.com/labstack/echo.git
synced 2025-07-15 01:34:53 +02:00
Add ability to set the logger on echo.Context (#1377)
This change allows middleware to replace the logger on the echo.Context with a customized per-request logger with additional fields. The logger is reset to default on every Reset() call.
This commit is contained in:
committed by
Vishal Rana
parent
c50c67783f
commit
5c7c87d09e
@ -7,6 +7,7 @@ import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/labstack/gommon/log"
|
||||
"io"
|
||||
"math"
|
||||
"mime/multipart"
|
||||
@ -800,7 +801,16 @@ func TestContext_Logger(t *testing.T) {
|
||||
e := New()
|
||||
c := e.NewContext(nil, nil)
|
||||
|
||||
testify.NotNil(t, c.Logger())
|
||||
log1 := c.Logger()
|
||||
testify.NotNil(t, log1)
|
||||
|
||||
log2 := log.New("echo2")
|
||||
c.SetLogger(log2)
|
||||
testify.Equal(t, log2, c.Logger())
|
||||
|
||||
// Resetting the context returns the initial logger
|
||||
c.Reset(nil, nil)
|
||||
testify.Equal(t, log1, c.Logger())
|
||||
}
|
||||
|
||||
func TestContext_RealIP(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user