Skip to content

Commit e57d898

Browse files
committed
Add heuristic logger calls
1 parent 9fc0dc5 commit e57d898

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

go/ql/lib/semmle/go/Concepts.qll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,28 @@ private class DefaultLoggerCall extends LoggerCall::Range, DataFlow::CallNode {
390390
}
391391
}
392392

393+
/**
394+
* A call to an interface that looks like a logger. It is common to use a
395+
* locally-defined interface for logging to make it easy to changing logging
396+
* library.
397+
*/
398+
private class HeuristicLoggerCall extends LoggerCall::Range, DataFlow::CallNode {
399+
HeuristicLoggerCall() {
400+
exists(Method m, string tp, string logLevel, string name |
401+
m = this.getTarget() and
402+
m.hasQualifiedName(_, tp, name) and
403+
m.getReceiverBaseType().getUnderlyingType() instanceof InterfaceType
404+
|
405+
tp.regexpMatch(".*[lL]ogger") and
406+
logLevel =
407+
["Debug", "Error", "Fatal", "Info", "Log", "Output", "Panic", "Print", "Trace", "Warn"] and
408+
name.matches(logLevel + "%")
409+
)
410+
}
411+
412+
override DataFlow::Node getAMessageComponent() { result = this.getASyntacticArgument() }
413+
}
414+
393415
/**
394416
* A function that encodes data into a binary or textual format.
395417
*

0 commit comments

Comments
 (0)