forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tracer.go
38 lines (30 loc) · 911 Bytes
/
tracer.go
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
// 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 topdown
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 *Context, 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 *Context, 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...)
}