[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

使用hook的方式让Logrus拥有输出日志时输出源代码所在文件和行号功能

License

Notifications You must be signed in to change notification settings

xdxiaodong/logrus-hook-caller

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Caller Hook for Logrus :walrus:

使用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")
}

About

使用hook的方式让Logrus拥有输出日志时输出源代码所在文件和行号功能

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages