Skip to content

Adjust cap log sinks #130

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

Merged
merged 2 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class CdsLogger extends MethodCallNode {
string getName() { result = name }
}

class ConstantOnlyTemplateLiteral extends TemplateLiteral {
ConstantOnlyTemplateLiteral() {
forall(Expr e | e = this.getAnElement() | e instanceof TemplateElement)
}
}

/**
* Arguments of calls to `cds.log.{trace, debug, info, log, warn, error}`
*/
Expand All @@ -31,7 +37,7 @@ class CdsLogSink extends DataFlow::Node {
this = loggingMethod.getAnArgument() and
loggingMethod.getMethodName() = ["trace", "debug", "info", "log", "warn", "error"] and
not this.asExpr() instanceof Literal and
not this.asExpr() instanceof TemplateLiteral and
not this.asExpr() instanceof ConstantOnlyTemplateLiteral and
loggingMethod.getReceiver().getALocalSource() = log
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
| logger.js:7:24:7:28 | code0 |
| logger.js:8:25:8:29 | code0 |
| logger.js:12:10:12:14 | code1 |
| logger.js:14:10:14:28 | `logging: ${code1}` |
3 changes: 3 additions & 0 deletions javascript/frameworks/cap/test/models/cds/logger/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ cds.log('nodejs').error(code0);
const code0 = "some-name";
const LOG = cds.log(code0);
LOG.info(code1);

LOG.info(`logging: ${code1}`);
LOG.info(`not actually logging`);