diff --git a/impl/pkg/dht/logger.go b/impl/pkg/dht/logger.go index 5539e847..532fb430 100644 --- a/impl/pkg/dht/logger.go +++ b/impl/pkg/dht/logger.go @@ -1,8 +1,6 @@ package dht import ( - "fmt" - "github.com/anacrolix/log" "github.com/sirupsen/logrus" ) @@ -10,21 +8,17 @@ import ( type logHandler struct{} func (logHandler) Handle(record log.Record) { - logrus.SetFormatter(&logrus.JSONFormatter{}) - entry := logrus.WithFields(logrus.Fields{"names": record.Names}) + msg := record.Msg.String() switch record.Level { case log.Debug: - entry.Debug(record.Msg.String()) + entry.Debugf("%s\n", msg) case log.Info: - entry.Info(record.Msg.String()) + entry.Infof("%s\n", msg) case log.Warning: - entry.Warn(record.Msg.String()) + entry.Warnf("%s\n", msg) default: - entry.Error(record.Msg.String()) + entry.Errorf("%s\n", msg) } - - // Add a newline character after each log message - fmt.Println() } diff --git a/impl/pkg/server/logging.go b/impl/pkg/server/logging.go index d9e1c5cc..51b8bd4d 100644 --- a/impl/pkg/server/logging.go +++ b/impl/pkg/server/logging.go @@ -63,7 +63,7 @@ func logger(logger logrus.FieldLogger, notLogged ...string) gin.HandlerFunc { if len(c.Errors) > 0 { entry.Error(c.Errors.ByType(gin.ErrorTypePrivate).String()) } else { - msg := fmt.Sprintf("%s - %s [%s] \"%s %s\" %d %d \"%s\" \"%s\" (%dms)", clientIP, hostname, time.Now().Format(timeFormat), c.Request.Method, path, statusCode, dataLength, referer, clientUserAgent, latency) + msg := fmt.Sprintf("%s - %s [%s] \"%s %s\" %d %d \"%s\" \"%s\" (%dms)\n", clientIP, hostname, time.Now().Format(timeFormat), c.Request.Method, path, statusCode, dataLength, referer, clientUserAgent, latency) if statusCode >= http.StatusInternalServerError { entry.Error(msg) } else if statusCode >= http.StatusBadRequest { @@ -72,8 +72,5 @@ func logger(logger logrus.FieldLogger, notLogged ...string) gin.HandlerFunc { entry.Info(msg) } } - - // Add a newline character after each log message - fmt.Println() } }