Skip to content

Commit a13c7a4

Browse files
authored
ESQL: Add sub-logger just for changes from rules (#132508)
Debugging the analyzer and optimizers is easier when we focus only on the changes they make to the query plan. Add a separate sub-logger to RuleExecutor so we can selectively enable only logging of those changes.
1 parent 3471987 commit a13c7a4

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/rule/RuleExecutor.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,25 @@
2121
public abstract class RuleExecutor<TreeType extends Node<TreeType>> {
2222

2323
private final Logger log = LogManager.getLogger(getClass());
24+
/**
25+
* Sub-logger intended to show only changes made by the rules. Intended for debugging.
26+
*
27+
* Enable it like this for the respective optimizers and the analyzer, resp. all inheritors of this class:
28+
* <pre>{@code
29+
* PUT localhost:9200/_cluster/settings
30+
*
31+
* {
32+
* "transient" : {
33+
* "logger.org.elasticsearch.xpack.esql.analysis.Analyzer.changes": "TRACE",
34+
* "logger.org.elasticsearch.xpack.esql.optimizer.LogicalPlanOptimizer.changes": "TRACE",
35+
* "logger.org.elasticsearch.xpack.esql.optimizer.LocalLogicalPlanOptimizer.changes": "TRACE",
36+
* "logger.org.elasticsearch.xpack.esql.optimizer.PhysicalPlanOptimizer.changes": "TRACE",
37+
* "logger.org.elasticsearch.xpack.esql.optimizer.LocalPhysicalPlanOptimizer.changes": "TRACE"
38+
* }
39+
* }
40+
* }</pre>
41+
*/
42+
private final Logger changeLog = LogManager.getLogger(getClass().getName() + ".changes");
2443

2544
public static class Limiter {
2645
public static final Limiter DEFAULT = new Limiter(100);
@@ -174,8 +193,8 @@ protected final ExecutionInfo executeWithInfo(TreeType plan) {
174193

175194
if (tf.hasChanged()) {
176195
hasChanged = true;
177-
if (log.isTraceEnabled()) {
178-
log.trace("Rule {} applied with change\n{}", rule, NodeUtils.diffString(tf.before, tf.after));
196+
if (changeLog.isTraceEnabled()) {
197+
changeLog.trace("Rule {} applied with change\n{}", rule, NodeUtils.diffString(tf.before, tf.after));
179198
}
180199
} else {
181200
if (log.isTraceEnabled()) {

0 commit comments

Comments
 (0)