logrusでログの行数とファイル名を出力したい
logrusを利用していて、ファイル名(filename)や行数(line number)を出力したくなったときは、
SetReportCaller(true)
という感じのメソッドを呼んでやればよい
package main import ( log "github.com/sirupsen/logrus" ) func main() { log.SetReportCaller(true) log.Error("hogehoge") }
出力サンプル
time="2019-10-11T03:20:45Z" level=error msg="UsernameExistsException: User account already exists\n\tstatus code: 400, request id: xxxx" func="github.com/hoge/hoge-api/domain/repository/common.(*cognitoRepository).Create" file="/go/src/api/domain/repository/common/cognito_repository.go:45"
※上記のコードとエラーの内容一致させてないので、そこはご了承ください。
関数名も教えてくれて便利。
以上