-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathLogrus.qll
More file actions
43 lines (35 loc) · 1.32 KB
/
Logrus.qll
File metadata and controls
43 lines (35 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/** Provides models of commonly used functions in the `github.com/sirupsen/logrus` package. */
overlay[local?]
module;
import go
/** Provides models of commonly used functions in the `github.com/sirupsen/logrus` package. */
module Logrus {
/** Gets the package name `github.com/sirupsen/logrus`. */
string packagePath() {
result = package(["github.com/sirupsen/logrus", "github.com/Sirupsen/logrus"], "")
}
bindingset[result]
private string getALogResultName() {
result.regexpMatch("(Debug|Error|Fatal|Info|Log|Panic|Print|Trace|Warn).*")
}
bindingset[result]
private string getAnEntryUpdatingMethodName() {
result = ["WithError", "WithField", "WithFields", "WithTime"]
}
private class LogFunction extends Function {
LogFunction() {
exists(string name | name = getALogResultName() or name = getAnEntryUpdatingMethodName() |
this.hasQualifiedName(packagePath(), name) or
this.(Method).hasQualifiedName(packagePath(), ["Entry", "Logger"], name)
)
}
}
private class StringFormatters extends StringOps::Formatting::Range instanceof LogFunction {
int argOffset;
StringFormatters() {
this.getName().matches("%f") and
if this.getName() = "Logf" then argOffset = 1 else argOffset = 0
}
override int getFormatStringIndex() { result = argOffset }
}
}