Caller Hook for Logrus ![:walrus: :walrus:](https://camo.githubusercontent.com/cad5cef19f4709026d903572dfb5fe5a75d090d95dd822ddef499e131e63337a/687474703a2f2f692e696d6775722e636f6d2f68546556776d4a2e706e67)
使用hook的方式让Logrus拥有输出日志时输出源代码所在文件和行号功能
package main
import (
log "github.com/sirupsen/logrus"
caller "github.com/xdxiaodong/logrus-hook-caller"
)
func main() {
log.SetFormatter(new(log.JSONFormatter))
hook_caller := caller.NewHook(&caller.CallerHookOptions{
//DisabledField: true,
//EnableFile: true,
//EnableLine: true,
//Flags: caller.Llongfile,
})
log.AddHook(hook_caller)
log.Info("hello world")
}
package main
import (
log "github.com/sirupsen/logrus"
caller "github.com/xdxiaodong/logrus-hook-caller"
)
func main() {
log.SetFormatter(new(log.JSONFormatter))
hook_caller := caller.NewHook(&caller.CallerHookOptions{
Flags: caller.Llongfile,
})
log.AddHook(hook_caller)
log.Info("hello world")
}