authorizer/server/logs/text.go

27 lines
593 B
Go
Raw Normal View History

2024-03-02 09:58:39 +00:00
package logs
import (
"fmt"
"strings"
2024-03-02 10:08:48 +00:00
"path/filepath"
2024-03-02 09:58:39 +00:00
"github.com/sirupsen/logrus"
)
2024-01-22 12:02:22 +00:00
// LogTextFormatter is a custom log formatter for text output
type LogTextFormatter struct {
logrus.Formatter
}
2024-03-02 09:55:46 +00:00
// Format helps formatting time to UTC
2024-01-22 12:02:22 +00:00
func (u LogTextFormatter) Format(e *logrus.Entry) ([]byte, error) {
2024-03-02 09:55:46 +00:00
timestamp := e.Time.Format("2006-01-02 15:04:05.000")
level := strings.ToUpper(e.Level.String())
message := e.Message
2024-03-02 10:08:48 +00:00
file := filepath.Base(e.Caller.File)
2024-03-02 09:55:46 +00:00
line := e.Caller.Line
2024-03-02 10:17:57 +00:00
return []byte(fmt.Sprintf("%s [%s] %s:%d %s\n", timestamp, level, file, line, message)), nil
2024-01-22 12:02:22 +00:00
}
2024-03-02 10:17:57 +00:00