microsoft/vscode-react-native

Public

mirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
bc7a32ce7b23591909f256ba627ef8e1fb8116a2

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/utils/commands/log.ts

46lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4/**
5 * Logging utility class.
6 */
7export class Log {
8
9 private static TAG: string = "[vscode-react-native]";
10
11 public static commandStarted(command: string) {
12 Log.logMessage(`Executing command: ${command}`);
13 }
14
15 public static commandEnded(command: string) {
16 Log.logMessage(`Finished executing: ${command}\n`);
17 }
18
19 public static commandFailed(command: string, error: any) {
20 Log.logError(`Error while executing: ${command}`, error);
21 }
22
23 /**
24 * Logs a message to the console.
25 */
26 public static logMessage(message: string) {
27 console.log(`${Log.TAG} ${message}`);
28 }
29
30 /**
31 * Logs an error message to the console.
32 */
33 public static logError(message: string, error?: any, logStack = true) {
34 console.error(`${Log.TAG} ${message} ${Log.getErrorMessage(error)}`);
35 if (logStack && error && (<Error>error).stack) {
36 console.error(`Stack: ${(<Error>error).stack}`);
37 }
38 }
39
40 /**
41 * Gets the message of an error, if any. Otherwise it returns the empty string.
42 */
43 public static getErrorMessage(e: any): string {
44 return e && e.message || e && e.error && e.error.message || e && e.toString() || "";
45 }
46}