First cut at adding calling method

If log.SetReportMethod(true) then method=PACKAGE.FUNCTION will be added
as a field to log lines.
eg: time="2016-11-25T19:04:43-08:00" level=info method=main msg="log
testing"

TODO: documentation, examples
This commit is contained in:
Dave Clendenan
2016-11-25 19:02:56 -08:00
parent a437dfd246
commit 93af604ba7
10 changed files with 248 additions and 20 deletions
+9 -1
View File
@@ -2,6 +2,7 @@ package logrus
import "time"
// DefaultTimestampFormat is YYYY-mm-DDTHH:MM:SS-TZ
const DefaultTimestampFormat = time.RFC3339
// The Formatter interface is used to implement a custom Formatter. It takes an
@@ -18,7 +19,7 @@ type Formatter interface {
Format(*Entry) ([]byte, error)
}
// This is to not silently overwrite `time`, `msg` and `level` fields when
// This is to not silently overwrite `time`, `msg`, `method` and `level` fields when
// dumping it. If this code wasn't there doing:
//
// logrus.WithField("level", 1).Info("hello")
@@ -42,4 +43,11 @@ func prefixFieldClashes(data Fields) {
if l, ok := data["level"]; ok {
data["fields.level"] = l
}
// If ReportMethod is not set, 'method' will not conflict.
if ReportMethod() {
if l, ok := data["method"]; ok {
data["fields.method"] = l
}
}
}