Skip to content

Commit 8702efd

Browse files
authored
Merge pull request github#13835 from github/smowton/fix/logrus-with-context
Don't treat logrus' WithContext method as a logging function
2 parents 5950865 + f08879a commit 8702efd

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Logrus' `WithContext` methods are no longer treated as if they output the values stored in that context to a log message.

go/ql/lib/semmle/go/frameworks/Logrus.qll

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ module Logrus {
1515
}
1616

1717
bindingset[result]
18-
private string getAnEntryUpdatingMethodName() {
19-
result.regexpMatch("With(Context|Error|Fields?|Time)")
20-
}
18+
private string getAnEntryUpdatingMethodName() { result.regexpMatch("With(Error|Fields?|Time)") }
2119

2220
private class LogFunction extends Function {
2321
LogFunction() {

go/ql/test/library-tests/semmle/go/concepts/LoggerCall/logrus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func logrusCalls() {
1818
var fields logrus.Fields = nil
1919
var fn logrus.LogFunction = nil
2020
var ctx context.Context
21-
tmp := logrus.WithContext(ctx) // $ logger=ctx
21+
tmp := logrus.WithContext(ctx) // ctx isn't output, so no match here
2222
tmp.Debugf(fmt, text) // $ logger=fmt logger=text
2323
tmp = logrus.WithError(err) // $ logger=err
2424
tmp.Warn(text) // $ logger=text

0 commit comments

Comments
 (0)