mirror of
https://github.com/golang/go
synced 2024-11-19 01:44:40 -07:00
e93be7f42f
Change-Id: I6aa47fffcb29842e3194231e4ad4b6be4386d329 Reviewed-on: https://go-review.googlesource.com/136675 Reviewed-by: Rebecca Stambler <rstambler@golang.org>
35 lines
787 B
Go
35 lines
787 B
Go
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package jsonrpc2
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"fmt"
|
|
"log"
|
|
)
|
|
|
|
// Log is an implementation of Logger that outputs using log.Print
|
|
// It is not used by default, but is provided for easy logging in users code.
|
|
func Log(mode string, id *ID, method string, payload *json.RawMessage, err *Error) {
|
|
buf := &bytes.Buffer{}
|
|
fmt.Fprint(buf, mode)
|
|
if id == nil {
|
|
fmt.Fprintf(buf, " []")
|
|
} else {
|
|
fmt.Fprintf(buf, " [%v]", id)
|
|
}
|
|
if method != "" {
|
|
fmt.Fprintf(buf, " %s", method)
|
|
}
|
|
if payload != nil {
|
|
fmt.Fprintf(buf, " %s", *payload)
|
|
}
|
|
if err != nil {
|
|
fmt.Fprintf(buf, " failed: %s", err)
|
|
}
|
|
log.Print(buf)
|
|
}
|