logfile
This commit is contained in:
parent
dc13f589c5
commit
e3360c3bfd
6
go.mod
6
go.mod
|
@ -1,3 +1,7 @@
|
|||
module github.com/smbrave/goutil
|
||||
|
||||
go 1.19
|
||||
go 1.18
|
||||
|
||||
require github.com/sirupsen/logrus v1.9.0
|
||||
|
||||
require golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package goutil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type LogFile struct {
|
||||
}
|
||||
|
||||
func (f *LogFile) Format(entry *log.Entry) ([]byte, error) {
|
||||
funcs := strings.SplitN(entry.Caller.Function, ".", 2)
|
||||
msg := fmt.Sprintf("[%s] [%s] [%s:%d] %s\n",
|
||||
entry.Time.Format("2006-01-02 15:04:05,000"),
|
||||
strings.ToUpper(entry.Level.String()),
|
||||
funcs[0]+"/"+filepath.Base(entry.Caller.File),
|
||||
entry.Caller.Line,
|
||||
entry.Message)
|
||||
return []byte(msg), nil
|
||||
}
|
Loading…
Reference in New Issue