mirror of
https://github.com/golang/go
synced 2024-11-18 14:54:40 -07:00
internal/lsp: purge the remains of the xlog system now it is not used
Change-Id: Iad8f037de88c2657734b8a1b5c73fc708d3b5924 Reviewed-on: https://go-review.googlesource.com/c/tools/+/186198 Run-TryBot: Ian Cottrell <iancottrell@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
73497f0562
commit
7caf8110c9
@ -21,7 +21,6 @@ import (
|
||||
"golang.org/x/tools/internal/lsp/protocol"
|
||||
"golang.org/x/tools/internal/lsp/source"
|
||||
"golang.org/x/tools/internal/lsp/tests"
|
||||
"golang.org/x/tools/internal/lsp/xlog"
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
@ -42,7 +41,6 @@ func testLSP(t *testing.T, exporter packagestest.Exporter) {
|
||||
data := tests.Load(t, exporter, "testdata")
|
||||
defer data.Exported.Cleanup()
|
||||
|
||||
ctx = xlog.With(ctx, xlog.StdSink{})
|
||||
cache := cache.New()
|
||||
session := cache.NewSession(ctx)
|
||||
view := session.NewView(ctx, viewName, span.FileURI(data.Config.Dir))
|
||||
|
@ -7,7 +7,6 @@ import (
|
||||
|
||||
"golang.org/x/tools/internal/lsp/telemetry/log"
|
||||
"golang.org/x/tools/internal/lsp/telemetry/tag"
|
||||
"golang.org/x/tools/internal/lsp/xlog"
|
||||
"golang.org/x/tools/internal/xcontext"
|
||||
)
|
||||
|
||||
@ -22,7 +21,6 @@ const (
|
||||
)
|
||||
|
||||
func WithClient(ctx context.Context, client Client) context.Context {
|
||||
ctx = xlog.With(ctx, logSink{client: client})
|
||||
return context.WithValue(ctx, clientKey, client)
|
||||
}
|
||||
|
||||
|
@ -1,25 +0,0 @@
|
||||
package protocol
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"golang.org/x/tools/internal/lsp/xlog"
|
||||
)
|
||||
|
||||
// logSink implements xlog.Sink in terms of the LogMessage call to a client.
|
||||
type logSink struct {
|
||||
client Client
|
||||
}
|
||||
|
||||
func (s logSink) Log(ctx context.Context, level xlog.Level, message string) {
|
||||
typ := Log
|
||||
switch level {
|
||||
case xlog.ErrorLevel:
|
||||
typ = Error
|
||||
case xlog.InfoLevel:
|
||||
typ = Info
|
||||
case xlog.DebugLevel:
|
||||
typ = Log
|
||||
}
|
||||
s.client.LogMessage(ctx, &LogMessageParams{Type: typ, Message: message})
|
||||
}
|
@ -19,7 +19,6 @@ import (
|
||||
"golang.org/x/tools/internal/lsp/diff"
|
||||
"golang.org/x/tools/internal/lsp/source"
|
||||
"golang.org/x/tools/internal/lsp/tests"
|
||||
"golang.org/x/tools/internal/lsp/xlog"
|
||||
"golang.org/x/tools/internal/span"
|
||||
)
|
||||
|
||||
@ -38,7 +37,6 @@ func testSource(t *testing.T, exporter packagestest.Exporter) {
|
||||
data := tests.Load(t, exporter, "../testdata")
|
||||
defer data.Exported.Cleanup()
|
||||
|
||||
ctx = xlog.With(ctx, xlog.StdSink{})
|
||||
cache := cache.New()
|
||||
session := cache.NewSession(ctx)
|
||||
r := &runner{
|
||||
|
@ -1,90 +0,0 @@
|
||||
// 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 xlog
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
)
|
||||
|
||||
// logger is a wrapper over a sink to provide a clean API over the core log
|
||||
// function.
|
||||
type logger struct {
|
||||
sink Sink
|
||||
}
|
||||
|
||||
// Level indicates the severity of the logging message.
|
||||
type Level int
|
||||
|
||||
const (
|
||||
ErrorLevel = Level(iota)
|
||||
InfoLevel
|
||||
DebugLevel
|
||||
)
|
||||
|
||||
// Sink is the interface to something that consumes logging messages.
|
||||
// This can be implemented and then registered with a context to control the
|
||||
// destination or formatting of logging.
|
||||
type Sink interface {
|
||||
Log(ctx context.Context, level Level, message string)
|
||||
}
|
||||
|
||||
// StdSink is a Sink that writes to the standard log package.
|
||||
type StdSink struct{}
|
||||
|
||||
// Errorf is intended for the logging of errors that we could not easily return
|
||||
// to the client but that caused problems internally.
|
||||
func (l logger) Errorf(ctx context.Context, format string, args ...interface{}) {
|
||||
l.sink.Log(ctx, ErrorLevel, fmt.Sprintf(format, args...))
|
||||
}
|
||||
|
||||
// Infof is intended for logging of messages that may help the user understand
|
||||
// the behavior or be useful in a bug report.
|
||||
func (l logger) Infof(ctx context.Context, format string, args ...interface{}) {
|
||||
l.sink.Log(ctx, InfoLevel, fmt.Sprintf(format, args...))
|
||||
}
|
||||
|
||||
// Debugf is intended to be used only while debugging.
|
||||
func (l logger) Debugf(ctx context.Context, format string, args ...interface{}) {
|
||||
l.sink.Log(ctx, DebugLevel, fmt.Sprintf(format, args...))
|
||||
}
|
||||
|
||||
// Log implements Sink for the StdSink.
|
||||
// It writes the message using log.Print with a level based prefix.
|
||||
func (StdSink) Log(ctx context.Context, level Level, message string) {
|
||||
switch level {
|
||||
case ErrorLevel:
|
||||
log.Print("Error: ", message)
|
||||
case InfoLevel:
|
||||
log.Print("Info: ", message)
|
||||
case DebugLevel:
|
||||
log.Print("Debug: ", message)
|
||||
}
|
||||
}
|
||||
|
||||
type contextKeyType int
|
||||
|
||||
const contextKey = contextKeyType(0)
|
||||
|
||||
func With(ctx context.Context, sink Sink) context.Context {
|
||||
return context.WithValue(ctx, contextKey, sink)
|
||||
}
|
||||
|
||||
func From(ctx context.Context) logger {
|
||||
return logger{sink: ctx.Value(contextKey).(Sink)}
|
||||
}
|
||||
|
||||
func Errorf(ctx context.Context, format string, args ...interface{}) {
|
||||
From(ctx).Errorf(ctx, format, args...)
|
||||
}
|
||||
|
||||
func Infof(ctx context.Context, format string, args ...interface{}) {
|
||||
From(ctx).Infof(ctx, format, args...)
|
||||
}
|
||||
|
||||
func Debugf(ctx context.Context, format string, args ...interface{}) {
|
||||
From(ctx).Debugf(ctx, format, args...)
|
||||
}
|
Loading…
Reference in New Issue
Block a user