This commit is contained in:
Dave Clendenan
2017-08-30 15:43:36 -07:00
7 changed files with 64 additions and 22 deletions
+5 -3
View File
@@ -66,6 +66,8 @@ To ensure this behaviour even if a TTY is attached, set your formatter as follow
})
```
#### Logging Method Name
If you wish to add the calling method as a field, instruct the logger via:
```go
log.SetReportCaller(true)
@@ -73,14 +75,14 @@ log.SetReportCaller(true)
This adds the caller as 'method' like so:
```json
{"animal":"penguin","level":"fatal","method":"arcticcreatures.migrate","msg":"a penguin swims by",
{"animal":"penguin","level":"fatal","method":"github.com/sirupsen/arcticcreatures.migrate","msg":"a penguin swims by",
"time":"2014-03-10 19:57:38.562543129 -0400 EDT"}
```
```text
time="2015-03-26T01:27:38-04:00" level=fatal method=arcticcreatures.migrate msg="a penguin swims by" animal=penguin
time="2015-03-26T01:27:38-04:00" level=fatal method=github.com/sirupsen/arcticcreatures.migrate msg="a penguin swims by" animal=penguin
```
Note that this does add measurable overhead - the cost will depend on the of Go, but is
Note that this does add measurable overhead - the cost will depend on the version of Go, but is
between 20 and 40% in recent tests with 1.6 and 1.7. You can validate this in your
environment via benchmarks:
```