forked from mirror/gin-logrus
Use interface to create logger
By using the FieldLogger interface the logger supports both new logrus loggers and existing field loggers such as an entry. This is useful if the enduser uses an existing logrus logger with existing fields.
This commit is contained in:
parent
8887861896
commit
4b2c7d212a
|
@ -19,7 +19,7 @@ import (
|
||||||
var timeFormat = "02/Jan/2006:15:04:05 -0700"
|
var timeFormat = "02/Jan/2006:15:04:05 -0700"
|
||||||
|
|
||||||
// Logger is the logrus logger handler
|
// Logger is the logrus logger handler
|
||||||
func Logger(log *logrus.Logger) gin.HandlerFunc {
|
func Logger(logger logrus.FieldLogger) gin.HandlerFunc {
|
||||||
hostname, err := os.Hostname()
|
hostname, err := os.Hostname()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
hostname = "unknow"
|
hostname = "unknow"
|
||||||
|
@ -40,7 +40,7 @@ func Logger(log *logrus.Logger) gin.HandlerFunc {
|
||||||
dataLength = 0
|
dataLength = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
entry := logrus.NewEntry(log).WithFields(logrus.Fields{
|
entry := logger.WithFields(logrus.Fields{
|
||||||
"hostname": hostname,
|
"hostname": hostname,
|
||||||
"statusCode": statusCode,
|
"statusCode": statusCode,
|
||||||
"latency": latency, // time to process
|
"latency": latency, // time to process
|
||||||
|
|
Loading…
Reference in New Issue