forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
262 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Gitpod. All rights reserved. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import * as vscode from 'vscode'; | ||
|
||
type LogLevel = 'Trace' | 'Info' | 'Error' | 'Warn' | 'Log'; | ||
|
||
export default class Log { | ||
private output: vscode.OutputChannel; | ||
|
||
constructor(name: string) { | ||
this.output = vscode.window.createOutputChannel(name); | ||
} | ||
|
||
private data2String(data: any): string { | ||
if (data instanceof Error) { | ||
return data.stack || data.message; | ||
} | ||
if (data.success === false && data.message) { | ||
return data.message; | ||
} | ||
return data.toString(); | ||
} | ||
|
||
public trace(message: string, data?: any): void { | ||
this.logLevel('Trace', message, data); | ||
} | ||
|
||
public info(message: string, data?: any): void { | ||
this.logLevel('Info', message, data); | ||
} | ||
|
||
public error(message: string, data?: any): void { | ||
this.logLevel('Error', message, data); | ||
} | ||
|
||
public warn(message: string, data?: any): void { | ||
this.logLevel('Warn', message, data); | ||
} | ||
|
||
public log(message: string, data?: any): void { | ||
this.logLevel('Log', message, data); | ||
} | ||
|
||
public logLevel(level: LogLevel, message: string, data?: any): void { | ||
this.output.appendLine(`[${level} - ${this.now()}] ${message}`); | ||
if (data) { | ||
this.output.appendLine(this.data2String(data)); | ||
} | ||
} | ||
|
||
private now(): string { | ||
const now = new Date(); | ||
return padLeft(now.getUTCHours() + '', 2, '0') | ||
+ ':' + padLeft(now.getMinutes() + '', 2, '0') | ||
+ ':' + padLeft(now.getUTCSeconds() + '', 2, '0') + '.' + now.getMilliseconds(); | ||
} | ||
|
||
public show() { | ||
this.output.show(); | ||
} | ||
} | ||
|
||
function padLeft(s: string, n: number, pad = ' ') { | ||
return pad.repeat(Math.max(0, n - s.length)) + s; | ||
} |
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 |
---|---|---|
|
@@ -505,6 +505,6 @@ | |
"vscode-jsonrpc": "^5.0.1", | ||
"vscode-nls": "^5.0.0", | ||
"yauzl": "^2.9.2", | ||
"yazl": "^2.4.3" | ||
"yazl": "^2.5.1" | ||
} | ||
} |
Oops, something went wrong.