mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 00:22:41 +08:00
logx
This commit is contained in:
28
logx/logrus_nested_formatter.go
Normal file
28
logx/logrus_nested_formatter.go
Normal file
@ -0,0 +1,28 @@
|
||||
package logx
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"runtime"
|
||||
|
||||
nested "github.com/antonfisher/nested-logrus-formatter"
|
||||
)
|
||||
|
||||
const defaultTimestampFormat = "2006-01-02 15:04:05.000"
|
||||
|
||||
type NestedFormatterOption struct {
|
||||
Color bool
|
||||
}
|
||||
|
||||
func NewNestedFormatter(option NestedFormatterOption) *nested.Formatter {
|
||||
return &nested.Formatter{
|
||||
TimestampFormat: defaultTimestampFormat,
|
||||
NoColors: !option.Color,
|
||||
CustomCallerFormatter: nestedCallerFormatter,
|
||||
}
|
||||
}
|
||||
|
||||
func nestedCallerFormatter(f *runtime.Frame) string {
|
||||
_, filename := path.Split(f.File)
|
||||
return fmt.Sprintf(" (%s() %s:%d)", f.Function, filename, f.Line)
|
||||
}
|
Reference in New Issue
Block a user