logs-fix-2
This commit is contained in:
parent
c8413665ae
commit
07a26991e9
|
@ -1,29 +1,26 @@
|
||||||
package logs
|
package logs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
log "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 {
|
type LogUTCFormatter struct {
|
||||||
log.Formatter
|
log.Formatter
|
||||||
}
|
}
|
||||||
|
|
||||||
// Format helps formatting time to UTC
|
// Format helps fomratting time to UTC
|
||||||
func (u LogUTCFormatter) Format(e *log.Entry) ([]byte, error) {
|
func (u LogUTCFormatter) Format(e *log.Entry) ([]byte, error) {
|
||||||
e.Time = e.Time.UTC()
|
e.Time = e.Time.UTC()
|
||||||
file := filepath.Base(e.Caller.File)
|
return u.Formatter.Format(e)
|
||||||
return []byte(fmt.Sprintf("[%s] %s:%d %s\n", e.Time.Format(time.RFC3339), file, e.Caller.Line, e.Message)), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitLog(cliLogLevel string) *log.Logger {
|
func InitLog(cliLogLevel string) *log.Logger {
|
||||||
// log instance for the gin server
|
|
||||||
|
// log instance for gin server
|
||||||
log := logrus.New()
|
log := logrus.New()
|
||||||
log.SetFormatter(LogUTCFormatter{&logrus.TextFormatter{}})
|
log.SetFormatter(LogUTCFormatter{&logrus.TextFormatter{}})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user