microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
4bd0c6691c098818360fd7858937bd9969fa5481

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/utils/commands/log.ts

55lines · 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 internal message for when someone is debugging the extension itself.
32 * Customers aren't interested in these messages, so we normally shouldn't show
33 * them to them.
34 */
35 public static logInternalMessage(message: string) {
36 console.log(`${Log.TAG}[Internal] ${message}`);
37 }
38
39 /**
40 * Logs an error message to the console.
41 */
42 public static logError(message: string, error?: any, logStack = true) {
43 console.error(`${Log.TAG} ${message} ${Log.getErrorMessage(error)}`);
44 if (logStack && error && (<Error>error).stack) {
45 console.error(`Stack: ${(<Error>error).stack}`);
46 }
47 }
48
49 /**
50 * Gets the message of an error, if any. Otherwise it returns the empty string.
51 */
52 public static getErrorMessage(e: Error): string {
53 return e && e.message || e && e.toString() || "";
54 }
55}