mirror of
https://github.com/labstack/echo.git
synced 2024-12-28 21:08:39 +02:00
Signed-off-by: Vishal Rana <vr@labstack.com>
This commit is contained in:
parent
3e04718bf4
commit
a98843b6e5
@ -12,7 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/labstack/echo/engine"
|
||||
"github.com/labstack/gommon/log"
|
||||
"github.com/labstack/echo/log"
|
||||
|
||||
"bytes"
|
||||
|
||||
@ -162,7 +162,7 @@ type (
|
||||
SetHandler(HandlerFunc)
|
||||
|
||||
// Logger returns the `Logger` instance.
|
||||
Logger() *log.Logger
|
||||
Logger() log.Logger
|
||||
|
||||
// Echo returns the `Echo` instance.
|
||||
Echo() *Echo
|
||||
@ -475,7 +475,7 @@ func (c *context) SetHandler(h HandlerFunc) {
|
||||
c.handler = h
|
||||
}
|
||||
|
||||
func (c *context) Logger() *log.Logger {
|
||||
func (c *context) Logger() log.Logger {
|
||||
return c.echo.logger
|
||||
}
|
||||
|
||||
|
36
echo.go
36
echo.go
@ -49,7 +49,8 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/labstack/echo/engine"
|
||||
"github.com/labstack/gommon/log"
|
||||
"github.com/labstack/echo/log"
|
||||
glog "github.com/labstack/gommon/log"
|
||||
)
|
||||
|
||||
type (
|
||||
@ -65,7 +66,7 @@ type (
|
||||
pool sync.Pool
|
||||
debug bool
|
||||
router *Router
|
||||
logger *log.Logger
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
// Route contains a handler and information for matching against requests.
|
||||
@ -225,9 +226,9 @@ func New() (e *Echo) {
|
||||
// Defaults
|
||||
e.SetHTTPErrorHandler(e.DefaultHTTPErrorHandler)
|
||||
e.SetBinder(&binder{})
|
||||
e.logger = log.New("echo")
|
||||
e.logger.SetLevel(log.ERROR)
|
||||
|
||||
l := glog.New("echo")
|
||||
l.SetLevel(glog.ERROR)
|
||||
e.SetLogger(l)
|
||||
return
|
||||
}
|
||||
|
||||
@ -248,9 +249,14 @@ func (e *Echo) Router() *Router {
|
||||
return e.router
|
||||
}
|
||||
|
||||
// SetLogPrefix sets the prefix for the logger. Default value is `echo`.
|
||||
func (e *Echo) SetLogPrefix(prefix string) {
|
||||
e.logger.SetPrefix(prefix)
|
||||
// Logger returns the logger instance.
|
||||
func (e *Echo) Logger() log.Logger {
|
||||
return e.logger
|
||||
}
|
||||
|
||||
// SetLogger defines a custom logger.
|
||||
func (e *Echo) SetLogger(l log.Logger) {
|
||||
e.logger = l
|
||||
}
|
||||
|
||||
// SetLogOutput sets the output destination for the logger. Default value is `os.Std*`
|
||||
@ -258,21 +264,11 @@ func (e *Echo) SetLogOutput(w io.Writer) {
|
||||
e.logger.SetOutput(w)
|
||||
}
|
||||
|
||||
// SetLogLevel sets the log level for the logger. Default value is `log.ERROR`.
|
||||
// SetLogLevel sets the log level for the logger. Default value is `glog.ERROR`.
|
||||
func (e *Echo) SetLogLevel(l uint8) {
|
||||
e.logger.SetLevel(l)
|
||||
}
|
||||
|
||||
// SetLogger defines a custom logger.
|
||||
func (e *Echo) SetLogger(l *log.Logger) {
|
||||
e.logger = l
|
||||
}
|
||||
|
||||
// Logger returns the logger instance.
|
||||
func (e *Echo) Logger() *log.Logger {
|
||||
return e.logger
|
||||
}
|
||||
|
||||
// DefaultHTTPErrorHandler invokes the default HTTP error handler.
|
||||
func (e *Echo) DefaultHTTPErrorHandler(err error, c Context) {
|
||||
code := http.StatusInternalServerError
|
||||
@ -313,7 +309,7 @@ func (e *Echo) SetRenderer(r Renderer) {
|
||||
// SetDebug enable/disable debug mode.
|
||||
func (e *Echo) SetDebug(on bool) {
|
||||
e.debug = on
|
||||
e.SetLogLevel(log.DEBUG)
|
||||
e.SetLogLevel(glog.DEBUG)
|
||||
}
|
||||
|
||||
// Debug returns debug mode (enabled or disabled).
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
|
||||
"net"
|
||||
|
||||
"github.com/labstack/gommon/log"
|
||||
"github.com/labstack/echo/log"
|
||||
)
|
||||
|
||||
type (
|
||||
@ -17,7 +17,7 @@ type (
|
||||
SetHandler(Handler)
|
||||
|
||||
// SetLogger sets the logger for the HTTP server.
|
||||
SetLogger(*log.Logger)
|
||||
SetLogger(log.Logger)
|
||||
|
||||
// Start starts the HTTP server.
|
||||
Start() error
|
||||
|
23
log/logger.go
Normal file
23
log/logger.go
Normal file
@ -0,0 +1,23 @@
|
||||
package log
|
||||
|
||||
import "io"
|
||||
|
||||
type (
|
||||
// Logger defines the logging interface.
|
||||
Logger interface {
|
||||
SetOutput(io.Writer)
|
||||
SetLevel(uint8)
|
||||
Print(...interface{})
|
||||
Printf(string, ...interface{})
|
||||
Debug(...interface{})
|
||||
Debugf(string, ...interface{})
|
||||
Info(...interface{})
|
||||
Infof(string, ...interface{})
|
||||
Warn(...interface{})
|
||||
Warnf(string, ...interface{})
|
||||
Error(...interface{})
|
||||
Errorf(string, ...interface{})
|
||||
Fatal(...interface{})
|
||||
Fatalf(string, ...interface{})
|
||||
}
|
||||
)
|
Loading…
Reference in New Issue
Block a user