@@ -103,101 +103,92 @@ func TestLogger(t *testing.T) {
103
103
assert .Equal (t , "[INFO] test: this is test: who=programmer why=[\" testing & qa\" , \" dev\" ]\n " , rest )
104
104
})
105
105
106
- t .Run ("formats multiline values nicely " , func (t * testing.T ) {
106
+ t .Run ("escapes quotes in values " , func (t * testing.T ) {
107
107
var buf bytes.Buffer
108
108
109
109
logger := New (& LoggerOptions {
110
110
Name : "test" ,
111
111
Output : & buf ,
112
112
})
113
113
114
- logger .Info ("this is test" , "who" , "programmer" , "why" , "testing \n and other \n pretty cool things" )
114
+ logger .Info ("this is test" , "who" , "programmer" , "why" , `this is "quoted"` )
115
115
116
116
str := buf .String ()
117
117
dataIdx := strings .IndexByte (str , ' ' )
118
118
rest := str [dataIdx + 1 :]
119
119
120
- expected := `[INFO] test: this is test: who=programmer
121
- why=
122
- | testing
123
- | and other
124
- | pretty cool things` + "\n \n "
125
- assert .Equal (t , expected , rest )
120
+ assert .Equal (t , `[INFO] test: this is test: who=programmer why="this is \"quoted\""` + "\n " , rest )
126
121
})
127
122
128
- t .Run ("outputs stack traces " , func (t * testing.T ) {
123
+ t .Run ("quotes when there are nonprintable sequences in a value " , func (t * testing.T ) {
129
124
var buf bytes.Buffer
130
125
131
126
logger := New (& LoggerOptions {
132
127
Name : "test" ,
133
128
Output : & buf ,
134
129
})
135
130
136
- logger .Info ("who" , "programmer" , "why" , "testing" , Stacktrace () )
131
+ logger .Info ("this is test" , " who" , "programmer" , "why" , "\U0001F603 " )
137
132
138
- lines := strings .Split (buf .String (), "\n " )
139
- require .True (t , len (lines ) > 1 )
133
+ str := buf .String ()
134
+ dataIdx := strings .IndexByte (str , ' ' )
135
+ rest := str [dataIdx + 1 :]
140
136
141
- assert .Equal (t , "github.com/hashicorp/go-hclog.Stacktrace" , lines [ 1 ] )
137
+ assert .Equal (t , "[INFO] test: this is test: who=programmer why= \" \U0001F603 \" \n " , rest )
142
138
})
143
139
144
- t .Run ("outputs stack traces with it's given a name " , func (t * testing.T ) {
140
+ t .Run ("formats multiline values nicely " , func (t * testing.T ) {
145
141
var buf bytes.Buffer
146
142
147
143
logger := New (& LoggerOptions {
148
144
Name : "test" ,
149
145
Output : & buf ,
150
146
})
151
147
152
- logger .Info ("who" , "programmer" , "why" , "testing" , "foo" , Stacktrace () )
148
+ logger .Info ("this is test" , " who" , "programmer" , "why" , "testing\n and other \n pretty cool things" )
153
149
154
- lines := strings .Split (buf .String (), "\n " )
155
- require .True (t , len (lines ) > 1 )
150
+ str := buf .String ()
151
+ dataIdx := strings .IndexByte (str , ' ' )
152
+ rest := str [dataIdx + 1 :]
156
153
157
- assert .Equal (t , "github.com/hashicorp/go-hclog.Stacktrace" , lines [1 ])
154
+ expected := `[INFO] test: this is test: who=programmer
155
+ why=
156
+ | testing
157
+ | and other
158
+ | pretty cool things` + "\n \n "
159
+ assert .Equal (t , expected , rest )
158
160
})
159
161
160
- t .Run ("includes the caller location " , func (t * testing.T ) {
162
+ t .Run ("outputs stack traces " , func (t * testing.T ) {
161
163
var buf bytes.Buffer
162
164
163
165
logger := New (& LoggerOptions {
164
- Name : "test" ,
165
- Output : & buf ,
166
- IncludeLocation : true ,
166
+ Name : "test" ,
167
+ Output : & buf ,
167
168
})
168
169
169
- logger .Info ("this is test" , " who" , "programmer" , "why" , "testing is fun" )
170
+ logger .Info ("who" , "programmer" , "why" , "testing" , Stacktrace () )
170
171
171
- str := buf .String ()
172
- dataIdx := strings .IndexByte (str , ' ' )
173
- rest := str [dataIdx + 1 :]
172
+ lines := strings .Split (buf .String (), "\n " )
173
+ require .True (t , len (lines ) > 1 )
174
174
175
- // This test will break if you move this around, it's line dependent, just fyi
176
- assert .Equal (t , "[INFO] go-hclog/logger_test.go:169: test: this is test: who=programmer why=\" testing is fun\" \n " , rest )
175
+ assert .Equal (t , "github.com/hashicorp/go-hclog.Stacktrace" , lines [1 ])
177
176
})
178
177
179
- t .Run ("includes the caller location excluding helper functions " , func (t * testing.T ) {
178
+ t .Run ("outputs stack traces with it's given a name " , func (t * testing.T ) {
180
179
var buf bytes.Buffer
181
180
182
- logMe := func (l Logger ) {
183
- l .Info ("this is test" , "who" , "programmer" , "why" , "testing is fun" )
184
- }
185
-
186
181
logger := New (& LoggerOptions {
187
- Name : "test" ,
188
- Output : & buf ,
189
- IncludeLocation : true ,
190
- AdditionalLocationOffset : 1 ,
182
+ Name : "test" ,
183
+ Output : & buf ,
191
184
})
192
185
193
- logMe ( logger )
186
+ logger . Info ( "who" , "programmer" , "why" , "testing" , "foo" , Stacktrace () )
194
187
195
- str := buf .String ()
196
- dataIdx := strings .IndexByte (str , ' ' )
197
- rest := str [dataIdx + 1 :]
188
+ lines := strings .Split (buf .String (), "\n " )
189
+ require .True (t , len (lines ) > 1 )
198
190
199
- // This test will break if you move this around, it's line dependent, just fyi
200
- assert .Equal (t , "[INFO] go-hclog/logger_test.go:193: test: this is test: who=programmer why=\" testing is fun\" \n " , rest )
191
+ assert .Equal (t , "github.com/hashicorp/go-hclog.Stacktrace" , lines [1 ])
201
192
})
202
193
203
194
t .Run ("prefixes the name" , func (t * testing.T ) {
0 commit comments