logs-fix-2

This commit is contained in:
Untone 2024-01-22 14:32:27 +03:00
parent c8413665ae
commit 07a26991e9

View File

@ -1,29 +1,26 @@
package logs
import (
"fmt"
"os"
"path/filepath"
"time"
"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"
)
// LogUTCFormatter helps in setting UTC time format for the logs
// LogUTCFormatter hels in setting UTC time format for the logs
type LogUTCFormatter struct {
log.Formatter
}
// Format helps formatting time to UTC
// Format helps fomratting time to UTC
func (u LogUTCFormatter) Format(e *log.Entry) ([]byte, error) {
e.Time = e.Time.UTC()
file := filepath.Base(e.Caller.File)
return []byte(fmt.Sprintf("[%s] %s:%d %s\n", e.Time.Format(time.RFC3339), file, e.Caller.Line, e.Message)), nil
return u.Formatter.Format(e)
}
func InitLog(cliLogLevel string) *log.Logger {
// log instance for the gin server
// log instance for gin server
log := logrus.New()
log.SetFormatter(LogUTCFormatter{&logrus.TextFormatter{}})