-
Notifications
You must be signed in to change notification settings - Fork 752
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src/goLogging.ts: add go.logging.level and log PATH mutation
go.logging.level determines the extension's debug logging level. Currently, all log messages go to console.log. Eventually, we will want to provide an option to output in an OUTPUT channel or a file. Add verbose logging to trace how the current GOROOT is determined and how PATH is mutated. Update #667 Change-Id: I95275ee4843d6cc9f8e34367f832a728ac1ea63f Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/256557 Trust: Hyang-Ah Hana Kim <hyangah@gmail.com> Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Suzy Mueller <suzmue@golang.org>
- Loading branch information
Showing
7 changed files
with
114 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/*--------------------------------------------------------- | ||
* Copyright 2020 The Go Authors. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE in the project root for license information. | ||
*--------------------------------------------------------*/ | ||
|
||
'use strict'; | ||
|
||
// Our log level. | ||
enum LogLevel { | ||
Off = 100, | ||
Error = 50, | ||
Info = 30, | ||
Verbose = 20, | ||
// TODO: Trace, Warn level | ||
} | ||
|
||
let currentLogLevel: LogLevel = LogLevel.Error; | ||
|
||
const levelMap: { [k: string]: LogLevel } = { | ||
off: LogLevel.Off, | ||
error: LogLevel.Error, | ||
info: LogLevel.Info, | ||
verbose: LogLevel.Verbose, | ||
}; | ||
|
||
function levelPrefix(l: LogLevel): string { | ||
switch (l) { | ||
case LogLevel.Off: return 'Go[O]:'; | ||
case LogLevel.Error: return 'Go[E]:'; | ||
case LogLevel.Info: return 'Go[I]:'; | ||
case LogLevel.Verbose: return 'Go[V]:'; | ||
default: return 'Go[?]:'; | ||
} | ||
} | ||
|
||
export interface LogConfig { | ||
level: string; | ||
} | ||
|
||
export function setLogConfig(cfg: LogConfig) { | ||
const logLevel = cfg?.level || 'error'; | ||
const l = levelMap[logLevel]; | ||
if (l) { | ||
currentLogLevel = l; | ||
return; | ||
} | ||
logError(`setLogLevel requested with invalid log level ${logLevel}, ignoring...`); | ||
} | ||
|
||
// tslint:disable-next-line:no-any | ||
function log(logLevel: LogLevel, ...args: any[]) { | ||
if (logLevel < currentLogLevel) { | ||
return; | ||
} | ||
const p = levelPrefix(logLevel); | ||
const a = Array.from(args); | ||
a.unshift(p); | ||
console.log(...a); | ||
// TODO: support logging in vscode output channel. | ||
} | ||
|
||
// tslint:disable-next-line:no-any | ||
export function logVerbose(...args: any[]) { | ||
log(LogLevel.Info, ...args); | ||
} | ||
|
||
// tslint:disable-next-line:no-any | ||
export function logError(...args: any[]) { | ||
log(LogLevel.Error, ...args); | ||
} | ||
|
||
// tslint:disable-next-line:no-any | ||
export function logInfo(...args: any[]) { | ||
log(LogLevel.Info, ...args); | ||
} |
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