From 5316af2acca4988e7732c48e35174eb0ee540c69 Mon Sep 17 00:00:00 2001 From: Will Faught Date: Mon, 16 Jan 2017 17:40:38 -0800 Subject: [PATCH] Change default file key string to caller --- log/stdlib.go | 4 ++-- log/stdlib_test.go | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/log/stdlib.go b/log/stdlib.go index 7ffd1ca17..ff96b5dee 100644 --- a/log/stdlib.go +++ b/log/stdlib.go @@ -39,7 +39,7 @@ func TimestampKey(key string) StdlibAdapterOption { return func(a *StdlibAdapter) { a.timestampKey = key } } -// FileKey sets the key for the file and line field. By default, it's "file". +// FileKey sets the key for the file and line field. By default, it's "caller". func FileKey(key string) StdlibAdapterOption { return func(a *StdlibAdapter) { a.fileKey = key } } @@ -55,7 +55,7 @@ func NewStdlibAdapter(logger Logger, options ...StdlibAdapterOption) io.Writer { a := StdlibAdapter{ Logger: logger, timestampKey: "ts", - fileKey: "file", + fileKey: "caller", messageKey: "msg", } for _, option := range options { diff --git a/log/stdlib_test.go b/log/stdlib_test.go index bdf94e8cd..90ebc5fa4 100644 --- a/log/stdlib_test.go +++ b/log/stdlib_test.go @@ -35,9 +35,9 @@ func TestStdlibAdapterUsage(t *testing.T) { log.Ldate: "ts=" + date + " msg=hello\n", log.Ltime: "ts=" + time + " msg=hello\n", log.Ldate | log.Ltime: "ts=\"" + date + " " + time + "\" msg=hello\n", - log.Lshortfile: "file=stdlib_test.go:44 msg=hello\n", - log.Lshortfile | log.Ldate: "ts=" + date + " file=stdlib_test.go:44 msg=hello\n", - log.Lshortfile | log.Ldate | log.Ltime: "ts=\"" + date + " " + time + "\" file=stdlib_test.go:44 msg=hello\n", + log.Lshortfile: "caller=stdlib_test.go:44 msg=hello\n", + log.Lshortfile | log.Ldate: "ts=" + date + " caller=stdlib_test.go:44 msg=hello\n", + log.Lshortfile | log.Ldate | log.Ltime: "ts=\"" + date + " " + time + "\" caller=stdlib_test.go:44 msg=hello\n", } { buf.Reset() stdlog.SetFlags(flag) @@ -58,11 +58,11 @@ func TestStdLibAdapterExtraction(t *testing.T) { "2009/01/23 01:23:23: hello": "ts=\"2009/01/23 01:23:23\" msg=hello\n", "01:23:23: hello": "ts=01:23:23 msg=hello\n", "2009/01/23 01:23:23.123123: hello": "ts=\"2009/01/23 01:23:23.123123\" msg=hello\n", - "2009/01/23 01:23:23.123123 /a/b/c/d.go:23: hello": "ts=\"2009/01/23 01:23:23.123123\" file=/a/b/c/d.go:23 msg=hello\n", - "01:23:23.123123 /a/b/c/d.go:23: hello": "ts=01:23:23.123123 file=/a/b/c/d.go:23 msg=hello\n", - "2009/01/23 01:23:23 /a/b/c/d.go:23: hello": "ts=\"2009/01/23 01:23:23\" file=/a/b/c/d.go:23 msg=hello\n", - "2009/01/23 /a/b/c/d.go:23: hello": "ts=2009/01/23 file=/a/b/c/d.go:23 msg=hello\n", - "/a/b/c/d.go:23: hello": "file=/a/b/c/d.go:23 msg=hello\n", + "2009/01/23 01:23:23.123123 /a/b/c/d.go:23: hello": "ts=\"2009/01/23 01:23:23.123123\" caller=/a/b/c/d.go:23 msg=hello\n", + "01:23:23.123123 /a/b/c/d.go:23: hello": "ts=01:23:23.123123 caller=/a/b/c/d.go:23 msg=hello\n", + "2009/01/23 01:23:23 /a/b/c/d.go:23: hello": "ts=\"2009/01/23 01:23:23\" caller=/a/b/c/d.go:23 msg=hello\n", + "2009/01/23 /a/b/c/d.go:23: hello": "ts=2009/01/23 caller=/a/b/c/d.go:23 msg=hello\n", + "/a/b/c/d.go:23: hello": "caller=/a/b/c/d.go:23 msg=hello\n", } { buf.Reset() fmt.Fprint(writer, input)