-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Emit messages for four main steps of the evaluation process: 1. new expression (eval) 2. trying to evaluate a plugged expression (try) 3. successfully evaluated a plugged expression (success) 4. finished evaluating a query (finish) Also refactored query interface slightly to take a params struct. This will be a bit more future proof.
- Loading branch information
Showing
5 changed files
with
193 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2016 The OPA Authors. All rights reserved. | ||
// Use of this source code is governed by an Apache2 | ||
// license that can be found in the LICENSE file. | ||
|
||
package eval | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// Tracer defines the interface for tracing evaluation. | ||
type Tracer interface { | ||
|
||
// Enabled returns true if the tracer is enabled. | ||
Enabled() bool | ||
|
||
// Trace emits a message if the tracer is enabled. | ||
Trace(ctx *TopDownContext, f string, a ...interface{}) | ||
} | ||
|
||
// StdoutTracer writes trace messages to stdout. | ||
type StdoutTracer struct{} | ||
|
||
// Enabled always returns true. | ||
func (t *StdoutTracer) Enabled() bool { return true } | ||
|
||
// Trace writes a trace message to stdout. | ||
func (t *StdoutTracer) Trace(ctx *TopDownContext, f string, a ...interface{}) { | ||
var padding string | ||
i := 0 | ||
for ; ctx != nil; ctx = ctx.Previous { | ||
padding += strings.Repeat(" ", ctx.Index+i) | ||
i++ | ||
} | ||
f = padding + f + "\n" | ||
fmt.Printf(f, a...) | ||
} |
Oops, something went wrong.