This commit is contained in:
jiangyong27 2023-02-08 22:12:15 +08:00
parent dc13f589c5
commit e3360c3bfd
2 changed files with 27 additions and 1 deletions

6
go.mod
View File

@ -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

22
logfile.go Normal file
View File

@ -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
}