mirror of
https://github.com/sourcegraph/jsonrpc2.git
synced 2026-06-27 13:03:41 +02:00
use custom logger for internal logging
Signed-off-by: s3rj1k <evasive.gyron@gmail.com>
This commit is contained in:
parent
8819199291
commit
6053545ad1
3 changed files with 20 additions and 16 deletions
|
|
@ -10,6 +10,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
)
|
||||
|
|
@ -296,6 +297,8 @@ type Conn struct {
|
|||
|
||||
disconnect chan struct{}
|
||||
|
||||
logger Logger
|
||||
|
||||
// Set by ConnOpt funcs.
|
||||
onRecv []func(*Request, *Response)
|
||||
onSend []func(*Request, *Response)
|
||||
|
|
@ -320,6 +323,7 @@ func NewConn(ctx context.Context, stream ObjectStream, h Handler, opts ...ConnOp
|
|||
h: h,
|
||||
pending: map[ID]*call{},
|
||||
disconnect: make(chan struct{}),
|
||||
logger: log.New(os.Stderr, "", log.LstdFlags),
|
||||
}
|
||||
for _, opt := range opts {
|
||||
if opt == nil {
|
||||
|
|
@ -542,7 +546,7 @@ func (c *Conn) readMessages(ctx context.Context) {
|
|||
|
||||
switch {
|
||||
case call == nil:
|
||||
log.Printf("jsonrpc2: ignoring response #%s with no corresponding request", id)
|
||||
c.logger.Printf("jsonrpc2: ignoring response #%s with no corresponding request\n", id)
|
||||
|
||||
case resp.Error != nil:
|
||||
call.done <- resp.Error
|
||||
|
|
@ -574,7 +578,7 @@ func (c *Conn) readMessages(ctx context.Context) {
|
|||
c.mu.Unlock()
|
||||
c.sending.Unlock()
|
||||
if err != io.ErrUnexpectedEOF && !closing {
|
||||
log.Println("jsonrpc2: protocol error:", err)
|
||||
c.logger.Printf("jsonrpc2: protocol error: %v\n", err)
|
||||
}
|
||||
close(c.disconnect)
|
||||
}
|
||||
|
|
@ -691,4 +695,3 @@ func (v *anyValueWithExplicitNull) UnmarshalJSON(data []byte) error {
|
|||
*v = anyValueWithExplicitNull{}
|
||||
return json.Unmarshal(data, &v.value)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue