ggzeng
10/21/2019 - 6:38 PM

logrus filename

打印日志所在文件名和行号

package main

import (
	"github.com/onrik/logrus/filename"
	log "github.com/sirupsen/logrus"
)

func main() {
	log.AddHook(filename.NewHook())  // 增加此hook会打印日志所在文件名和行号
	log.Println("something")
	t := T{}
	t.method()
}

type T struct {
}

func (t *T) method() {
	log.Println("in method")
}

// <output>
// time="2009-11-10T23:00:00Z" level=info msg=something _source="sandbox475278919/prog.go:10"
// time="2009-11-10T23:00:00Z" level=info msg="in method" _source="sandbox475278919/prog.go:19"