@@ -16,6 +16,7 @@ package adt
16
16
17
17
import (
18
18
"fmt"
19
+ "log"
19
20
"os"
20
21
"reflect"
21
22
"regexp"
@@ -34,6 +35,11 @@ import (
34
35
// false otherwise.
35
36
var Debug bool = os .Getenv ("CUE_DEBUG" ) != "0"
36
37
38
+ // Verbosity sets the log level. There are currently only two levels:
39
+ // 0: no logging
40
+ // 1: logging
41
+ var Verbosity int
42
+
37
43
// Assert panics if the condition is false. Assert can be used to check for
38
44
// conditions that are considers to break an internal variant or unexpected
39
45
// condition, but that nonetheless probably will be handled correctly down the
@@ -59,6 +65,43 @@ func (c *OpContext) Assertf(pos token.Pos, b bool, format string, args ...interf
59
65
}
60
66
}
61
67
68
+ func init () {
69
+ log .SetFlags (log .Lshortfile )
70
+ }
71
+
72
+ func Logf (format string , args ... interface {}) {
73
+ if Verbosity == 0 {
74
+ return
75
+ }
76
+ s := fmt .Sprintf (format , args ... )
77
+ _ = log .Output (2 , s )
78
+ }
79
+
80
+ var pMap = map [* Vertex ]int {}
81
+
82
+ func (c * OpContext ) Logf (v * Vertex , format string , args ... interface {}) {
83
+ if Verbosity == 0 {
84
+ return
85
+ }
86
+ p := pMap [v ]
87
+ if p == 0 {
88
+ p = len (pMap ) + 1
89
+ pMap [v ] = p
90
+ }
91
+ a := append ([]interface {}{
92
+ p ,
93
+ v .Label .SelectorString (c ),
94
+ v .Path (),
95
+ }, args ... )
96
+ for i := 2 ; i < len (a ); i ++ {
97
+ if n , ok := a [i ].(Node ); ok {
98
+ a [i ] = c .Str (n )
99
+ }
100
+ }
101
+ s := fmt .Sprintf (" [%d] %s/%v" + format , a ... )
102
+ _ = log .Output (2 , s )
103
+ }
104
+
62
105
// A Unifier implements a strategy for CUE's unification operation. It must
63
106
// handle the following aspects of CUE evaluation:
64
107
//
0 commit comments