-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
internal/lsp/debug: hook runtime/trace into event spans
Existing spans defined within gopls are leveraged to add runtime/trace tasks, regions, and logging. This made it easier to understand gopls' execution, though we still have relatively sparse logging (arguably because we're conscious of the fact that logs are reflected back to the LSP client). Add a new log package with the concept of log level to facilitate excluding trace logs from the LSP. Add a little bit of additional instrumentation to demonstrate the usage of the new package. Change-Id: Id337be806484201103e30bfe2c8c62c7d7c363c7 Reviewed-on: https://go-review.googlesource.com/c/tools/+/275252 Run-TryBot: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]> Trust: Robert Findley <[email protected]>
- Loading branch information
Showing
6 changed files
with
140 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2020 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 log provides helper methods for exporting log events to the | ||
// internal/event package. | ||
package log | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"golang.org/x/tools/internal/event" | ||
"golang.org/x/tools/internal/event/label" | ||
"golang.org/x/tools/internal/lsp/debug/tag" | ||
) | ||
|
||
// Level parameterizes log severity. | ||
type Level int | ||
|
||
const ( | ||
_ Level = iota | ||
Error | ||
Warning | ||
Info | ||
Debug | ||
Trace | ||
) | ||
|
||
// Log exports a log event labeled with level l. | ||
func (l Level) Log(ctx context.Context, msg string) { | ||
event.Log(ctx, msg, tag.Level.Of(int(l))) | ||
} | ||
|
||
// Logf formats and exports a log event labeled with level l. | ||
func (l Level) Logf(ctx context.Context, format string, args ...interface{}) { | ||
l.Log(ctx, fmt.Sprintf(format, args...)) | ||
} | ||
|
||
// LabeledLevel extracts the labeled log l | ||
func LabeledLevel(lm label.Map) Level { | ||
return Level(tag.Level.Get(lm)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters