microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
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 | */ |
| 7 | export 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 | } |