-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Rename file term to caller #437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,7 +27,7 @@ func (w StdlibWriter) Write(p []byte) (int, error) { | |
| type StdlibAdapter struct { | ||
| Logger | ||
| timestampKey string | ||
| fileKey string | ||
| callerKey string | ||
| messageKey string | ||
| } | ||
|
|
||
|
|
@@ -39,9 +39,9 @@ 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". | ||
| func FileKey(key string) StdlibAdapterOption { | ||
| return func(a *StdlibAdapter) { a.fileKey = key } | ||
| // CallerKey sets the key for the file and line field. By default, it's "caller". | ||
| func CallerKey(key string) StdlibAdapterOption { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To preserve backwards compatibility, could we leave the name of the option as |
||
| return func(a *StdlibAdapter) { a.callerKey = key } | ||
| } | ||
|
|
||
| // MessageKey sets the key for the actual log message. By default, it's "msg". | ||
|
|
@@ -55,7 +55,7 @@ func NewStdlibAdapter(logger Logger, options ...StdlibAdapterOption) io.Writer { | |
| a := StdlibAdapter{ | ||
| Logger: logger, | ||
| timestampKey: "ts", | ||
| fileKey: "file", | ||
| callerKey: "caller", | ||
| messageKey: "msg", | ||
| } | ||
| for _, option := range options { | ||
|
|
@@ -80,8 +80,8 @@ func (a StdlibAdapter) Write(p []byte) (int, error) { | |
| if timestamp != "" { | ||
| keyvals = append(keyvals, a.timestampKey, timestamp) | ||
| } | ||
| if file, ok := result["file"]; ok && file != "" { | ||
| keyvals = append(keyvals, a.fileKey, file) | ||
| if caller, ok := result["caller"]; ok && caller != "" { | ||
| keyvals = append(keyvals, a.callerKey, caller) | ||
| } | ||
| if msg, ok := result["msg"]; ok { | ||
| keyvals = append(keyvals, a.messageKey, msg) | ||
|
|
@@ -93,14 +93,14 @@ func (a StdlibAdapter) Write(p []byte) (int, error) { | |
| } | ||
|
|
||
| const ( | ||
| logRegexpDate = `(?P<date>[0-9]{4}/[0-9]{2}/[0-9]{2})?[ ]?` | ||
| logRegexpTime = `(?P<time>[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]+)?)?[ ]?` | ||
| logRegexpFile = `(?P<file>.+?:[0-9]+)?` | ||
| logRegexpMsg = `(: )?(?P<msg>.*)` | ||
| logRegexpDate = `(?P<date>[0-9]{4}/[0-9]{2}/[0-9]{2})?[ ]?` | ||
| logRegexpTime = `(?P<time>[0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]+)?)?[ ]?` | ||
| logRegexpCaller = `(?P<caller>.+?:[0-9]+)?` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And likewise leave this as |
||
| logRegexpMsg = `(: )?(?P<msg>.*)` | ||
| ) | ||
|
|
||
| var ( | ||
| logRegexp = regexp.MustCompile(logRegexpDate + logRegexpTime + logRegexpFile + logRegexpMsg) | ||
| logRegexp = regexp.MustCompile(logRegexpDate + logRegexpTime + logRegexpCaller + logRegexpMsg) | ||
| ) | ||
|
|
||
| func subexps(line []byte) map[string]string { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise leave this as
fileKeywith a default value of"caller"