Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit d6a523c

Browse files
Amin Jamalireneighbor
authored andcommitted
Remove extra newline that was written to cf logs output
* This line is necessary in the access log (WriteTo) so they show up as distinct lines * It was redundant in `cf logs` (LogMessage); this was problematic because it sent extra envelopes through the loggregator system. Fixes cloudfoundry/routing-release#124 Fixes #202 Co-authored-by: Renee Chu <[email protected]>
1 parent 475bcdd commit d6a523c

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

accesslog/file_and_loggregator_access_logger_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ var _ = Describe("AccessLog", func() {
5252
Eventually(ls.SendAppLogCallCount).Should(Equal(1))
5353
appID, message, tags := ls.SendAppLogArgsForCall(0)
5454
Expect(appID).To(Equal("my_awesome_id"))
55-
Expect(message).To(MatchRegexp("^.*foo.bar.*\n"))
55+
Expect(message).To(MatchRegexp("^.*foo.bar.*"))
5656
Expect(tags).To(BeNil())
5757

5858
accessLogger.Stop()

accesslog/schema/access_log_record.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package schema
22

33
import (
44
"bytes"
5-
"code.cloudfoundry.org/gorouter/config"
65
"crypto/sha1"
76
"encoding/hex"
87
"fmt"
@@ -12,6 +11,8 @@ import (
1211
"strings"
1312
"time"
1413

14+
"code.cloudfoundry.org/gorouter/config"
15+
1516
"code.cloudfoundry.org/gorouter/route"
1617
)
1718

@@ -203,8 +204,6 @@ func (r *AccessLogRecord) makeRecord() []byte {
203204

204205
r.addExtraHeaders(b)
205206

206-
b.WriteByte('\n')
207-
208207
return b.Bytes()
209208
}
210209

@@ -230,7 +229,11 @@ func redactURI(r AccessLogRecord) string {
230229
// WriteTo allows the AccessLogRecord to implement the io.WriterTo interface
231230
func (r *AccessLogRecord) WriteTo(w io.Writer) (int64, error) {
232231
bytesWritten, err := w.Write(r.getRecord())
233-
return int64(bytesWritten), err
232+
if err != nil {
233+
return int64(bytesWritten), err
234+
}
235+
newline, err := w.Write([]byte("\n"))
236+
return int64(bytesWritten + newline), err
234237
}
235238

236239
func (r *AccessLogRecord) SendLog(ls LogSender) {

accesslog/schema/access_log_record_test.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package schema_test
22

33
import (
44
"bytes"
5+
56
"code.cloudfoundry.org/gorouter/accesslog/schema"
67
"code.cloudfoundry.org/gorouter/config"
78
"code.cloudfoundry.org/gorouter/handlers"
@@ -68,7 +69,7 @@ var _ = Describe("AccessLogRecord", func() {
6869
Eventually(r).Should(Say(`x_forwarded_proto:"FakeOriginalRequestProto" `))
6970
Eventually(r).Should(Say(`vcap_request_id:"abc-123-xyz-pdq" response_time:60.000000 gorouter_time:10.000000 app_id:"FakeApplicationId" `))
7071
Eventually(r).Should(Say(`app_index:"3"`))
71-
Eventually(r).Should(Say(`x_cf_routererror:"some-router-error"\n`))
72+
Eventually(r).Should(Say(`x_cf_routererror:"some-router-error"`))
7273
})
7374

7475
Context("when DisableSourceIPLogging is specified", func() {
@@ -153,7 +154,7 @@ var _ = Describe("AccessLogRecord", func() {
153154
Eventually(r).Should(Say(`x_forwarded_proto:"FooOriginalRequestProto" `))
154155
Eventually(r).Should(Say(`vcap_request_id:"abc-123-xyz-pdq" response_time:60.000000 gorouter_time:10.000000 app_id:"FakeApplicationId" `))
155156
Eventually(r).Should(Say(`app_index:"3"`))
156-
Eventually(r).Should(Say(`x_cf_routererror:"some-router-error"\n`))
157+
Eventually(r).Should(Say(`x_cf_routererror:"some-router-error"`))
157158
})
158159
})
159160

@@ -181,7 +182,7 @@ var _ = Describe("AccessLogRecord", func() {
181182
Eventually(r).Should(Say(`x_forwarded_proto:"-" `))
182183
Eventually(r).Should(Say(`vcap_request_id:"-" response_time:"-" gorouter_time:"-" app_id:"FakeApplicationId" `))
183184
Eventually(r).Should(Say(`app_index:"-"`))
184-
Eventually(r).Should(Say(`x_cf_routererror:"-"\n`))
185+
Eventually(r).Should(Say(`x_cf_routererror:"-"`))
185186
})
186187
})
187188

@@ -212,7 +213,7 @@ var _ = Describe("AccessLogRecord", func() {
212213
Eventually(r).Should(Say(`x_forwarded_proto:"FakeOriginalRequestProto" `))
213214
Eventually(r).Should(Say(`vcap_request_id:"abc-123-xyz-pdq" response_time:60.000000 gorouter_time:10.000000 app_id:"FakeApplicationId" `))
214215
Eventually(r).Should(Say(`app_index:"3" x_cf_routererror:"some-router-error" cache_control:"no-cache" accept_encoding:"gzip, deflate" `))
215-
Eventually(r).Should(Say(`if_match:"737060cd8c284d8af7ad3082f209582d" doesnt_exist:"-"\n`))
216+
Eventually(r).Should(Say(`if_match:"737060cd8c284d8af7ad3082f209582d" doesnt_exist:"-"`))
216217
})
217218
})
218219

@@ -254,7 +255,7 @@ var _ = Describe("AccessLogRecord", func() {
254255
Eventually(r).Should(Say(`x_forwarded_proto:"FakeOriginalRequestProto" `))
255256
Eventually(r).Should(Say(`vcap_request_id:"abc-123-xyz-pdq" response_time:60.000000 gorouter_time:10.000000 app_id:"FakeApplicationId" `))
256257
Eventually(r).Should(Say(`app_index:"3"`))
257-
Eventually(r).Should(Say(`x_cf_routererror:"-"\n`))
258+
Eventually(r).Should(Say(`x_cf_routererror:"-"`))
258259
})
259260
})
260261
})

0 commit comments

Comments
 (0)