microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
a31b007c2af965bbb579b8e9ae0054a403891c95

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/utils/commands/log.ts

43lines · 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);
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(mssage: string, error: any) {
34 console.error(Log.TAG + " " + mssage + " " + Log.getErrorMessage(error));
35 }
36
37 /**
38 * Gets the message of an error, if any. Otherwise it returns the empty string.
39 */
40 public static getErrorMessage(e: Error): string {
41 return e && e.message || e && e.toString() || "";
42 }
43}