mirror of
https://github.com/sourcegraph/jsonrpc2.git
synced 2026-07-04 16:23:41 +02:00
Replaced log.Logger parameter by interface (#20)
This commit is contained in:
parent
073230af28
commit
549eb959f0
1 changed files with 7 additions and 2 deletions
|
|
@ -2,10 +2,15 @@ package jsonrpc2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Logger interface implements one method - Printf.
|
||||||
|
// You can use the stdlib logger *log.Logger
|
||||||
|
type Logger interface {
|
||||||
|
Printf(format string, v ...interface{})
|
||||||
|
}
|
||||||
|
|
||||||
// ConnOpt is the type of function that can be passed to NewConn to
|
// ConnOpt is the type of function that can be passed to NewConn to
|
||||||
// customize the Conn before it is created.
|
// customize the Conn before it is created.
|
||||||
type ConnOpt func(*Conn)
|
type ConnOpt func(*Conn)
|
||||||
|
|
@ -24,7 +29,7 @@ func OnSend(f func(*Request, *Response)) ConnOpt {
|
||||||
|
|
||||||
// LogMessages causes all messages sent and received on conn to be
|
// LogMessages causes all messages sent and received on conn to be
|
||||||
// logged using the provided logger.
|
// logged using the provided logger.
|
||||||
func LogMessages(log *log.Logger) ConnOpt {
|
func LogMessages(log Logger) ConnOpt {
|
||||||
return func(c *Conn) {
|
return func(c *Conn) {
|
||||||
// Remember reqs we have received so we can helpfully show the
|
// Remember reqs we have received so we can helpfully show the
|
||||||
// request method in OnSend for responses.
|
// request method in OnSend for responses.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue