Skip to content

Commit

Permalink
hopefully last one
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe committed Apr 10, 2024
1 parent 49f894e commit aad77e0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
16 changes: 5 additions & 11 deletions impl/pkg/dht/logger.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
package dht

import (
"fmt"

"github.com/anacrolix/log"
"github.com/sirupsen/logrus"
)

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()
}
5 changes: 1 addition & 4 deletions impl/pkg/server/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
}
}

0 comments on commit aad77e0

Please sign in to comment.