microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.10.1

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/extension/log/ConsoleLogger.ts

46lines · modeblame

0a68f8dbArtem Egorov8 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import {ILogger, LogLevel, LogHelper} from "./LogHelper";
5
6export class ConsoleLogger implements ILogger {
7public log(message: string, level: LogLevel): void {
8if (LogHelper.LOG_LEVEL === LogLevel.None) {
9return;
10}
11
12if (level >= LogHelper.LOG_LEVEL) {
13message = ConsoleLogger.getFormattedMessage(message, level);
14console.log(message);
15}
16}
17
18public info(message: string): void {
19this.log(message, LogLevel.Info);
20}
21
22public warning(message: string, logStack = false): void {
23this.log(message, LogLevel.Warning);
24}
25
26public error(errorMessage: string, error?: Error, logStack: boolean = true) {
27console.error(ConsoleLogger.getFormattedMessage(errorMessage, LogLevel.Error));
28
29// Print the error stack if necessary
30if (logStack && error && (<Error>error).stack) {
31console.error(`Stack: ${(<Error>error).stack}`);
32}
33}
34
35public debug(message: string): void {
36this.log(message, LogLevel.Debug);
37}
38
39public logStream(data: Buffer, stream: NodeJS.WritableStream) {
40stream.write(data.toString());
41}
42
43protected static getFormattedMessage(message: string, level: LogLevel): string {
44return `[${LogLevel[level]}] ${message}\n`;
45}
46}