1
0
mirror of https://github.com/golang/go synced 2024-10-01 10:38:33 -06:00
go/internal/jsonrpc2/log.go
Ian Cottrell e93be7f42f internal/jsonrpc2: a basic json rpc library to build an lsp on top of
Change-Id: I6aa47fffcb29842e3194231e4ad4b6be4386d329
Reviewed-on: https://go-review.googlesource.com/136675
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
2018-09-24 17:56:01 +00:00

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)
}