Skip to content

Commit cdfd535

Browse files
committed
log: use bytes.Buffer
1 parent 74048ad commit cdfd535

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

log.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
// SPDX-License-Identifier: BSD-3-Clause
21
// SPDX-FileCopyrightText: Copyright 2021 The Go Language Server Authors
2+
// SPDX-License-Identifier: BSD-3-Clause
33

44
package protocol
55

66
import (
7+
"bytes"
78
"context"
89
"fmt"
910
"io"
10-
"strings"
1111
"sync"
1212
"time"
1313

@@ -106,7 +106,6 @@ func (s *loggingStream) logCommon(msg jsonrpc2.Message, isRead bool) {
106106
}
107107

108108
s.logMu.Lock()
109-
defer s.logMu.Unlock()
110109

111110
direction, pastTense := "Received", "Received"
112111
get, set := maps.client, maps.setServer
@@ -118,7 +117,7 @@ func (s *loggingStream) logCommon(msg jsonrpc2.Message, isRead bool) {
118117
tm := time.Now()
119118
tmfmt := tm.Format("15:04:05.000 PM")
120119

121-
var buf strings.Builder
120+
var buf bytes.Buffer
122121
fmt.Fprintf(&buf, "[Trace - %s] ", tmfmt) // common beginning
123122

124123
switch msg := msg.(type) {
@@ -145,5 +144,7 @@ func (s *loggingStream) logCommon(msg jsonrpc2.Message, isRead bool) {
145144
fmt.Fprintf(&buf, "Result: %s%s", msg.Result(), eor)
146145
}
147146

148-
s.log.Write([]byte(buf.String()))
147+
s.log.Write(buf.Bytes())
148+
149+
s.logMu.Unlock()
149150
}

0 commit comments

Comments
 (0)