-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Runme logging in output channel (#521)
* Improve logging * colored error logging * remove demo lines * Update src/extension/survey.ts Co-authored-by: Max Stoumen <max@mxs.dev> * Update src/extension/survey.ts Co-authored-by: Max Stoumen <max@mxs.dev> * Update src/extension/logger.ts Co-authored-by: Max Stoumen <max@mxs.dev> * Update src/extension/index.ts Co-authored-by: Max Stoumen <max@mxs.dev> * PR feedback * make logLevel uppercase * re-use strip ansi regex --------- Co-authored-by: Max Stoumen <max@mxs.dev>
- Loading branch information
1 parent
ae4e6d9
commit 7533440
Showing
15 changed files
with
104 additions
and
23 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
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,48 @@ | ||
import util from 'node:util' | ||
|
||
import { window } from 'vscode' | ||
|
||
import { stripANSI } from '../utils/ansi' | ||
|
||
const outputChannel = window.createOutputChannel('Runme') | ||
|
||
const DEFAULT_LOG_LEVEL: LogLevel = 'info' | ||
|
||
/** | ||
* VS Code currently doesn't support colors, see | ||
* https://github.com/microsoft/vscode/issues/571 | ||
* Therefor keep this minimal. | ||
*/ | ||
const colors = { | ||
reset: '\x1b[0m', | ||
red: '\x1b[31m', | ||
green: '\x1b[32m', | ||
yellow: '\x1b[33m' | ||
} as const | ||
type LogLevel = 'trace' | 'info' | 'warn' | 'error' | ||
|
||
function color (color: keyof typeof colors, text: string) { | ||
return `${colors[color]}${text}${colors.reset}` | ||
} | ||
|
||
function log (scope?: string, logLevel: LogLevel = DEFAULT_LOG_LEVEL, ...logParams: string[]) { | ||
const now = new Date() | ||
const scopeAddition = scope ? color('yellow', `(${scope})`) : '' | ||
const prefix = util.format( | ||
`${color('green' ,'[%s]')} ${color('yellow', '%s')} Runme%s:`, | ||
now.toISOString(), | ||
(logLevel && logLevel.toUpperCase()) ?? '', | ||
scopeAddition | ||
) | ||
console.log(prefix, ...logParams) | ||
outputChannel.appendLine(stripANSI([prefix, ...logParams].join(' '))) | ||
} | ||
|
||
export default function getLogger (scope?: string) { | ||
return { | ||
trace: (...logParams: string[]) => log(scope, 'trace', ...logParams), | ||
info: (...logParams: string[]) => log(scope, 'info', ...logParams), | ||
warn: (...logParams: string[]) => log(scope, 'warn', ...logParams), | ||
error: (...logParams: string[]) => log(scope, 'error', ...logParams) | ||
} | ||
} |
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
Oops, something went wrong.