https://github.com/xdxiaodong/logrus-hook-caller
使用hook的方式让Logrus拥有输出日志时输出源代码所在文件和行号功能
https://github.com/xdxiaodong/logrus-hook-caller
caller logrus logrus-hook
Last synced: 8 months ago
JSON representation
使用hook的方式让Logrus拥有输出日志时输出源代码所在文件和行号功能
- Host: GitHub
- URL: https://github.com/xdxiaodong/logrus-hook-caller
- Owner: xdxiaodong
- License: apache-2.0
- Created: 2018-05-06T14:11:12.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-05-10T10:21:05.000Z (about 8 years ago)
- Last Synced: 2025-08-13T22:47:03.633Z (10 months ago)
- Topics: caller, logrus, logrus-hook
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 4
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Caller Hook for [Logrus](https://github.com/sirupsen/logrus) 
使用hook的方式让Logrus拥有输出日志时输出源代码所在文件和行号功能
## 示例
### 默认
```go
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")
}
```
### 源文件完整路径
```go
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")
}
```