microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
0.14.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/log/LogHelper.ts

68lines · 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
4/**
5* Logging utility class.
6*/
08722261Yuri Skorokhodov7 years ago7import * as path from "path";
8import * as mkdirp from "mkdirp";
0a68f8dbArtem Egorov8 years ago9export enum LogLevel {
10Trace = 0,
11Debug = 1,
12Info = 2,
13Warning = 3,
14Error = 4,
15None = 5,
16}
17
18export interface ILogger {
19log: (message: string, level: LogLevel) => void;
20info: (message: string) => void;
21warning: (message: string) => void;
22error: (errorMessage: string, error?: Error, stack?: boolean) => void;
23debug: (message: string) => void;
24logStream: (data: Buffer | String, stream?: NodeJS.WritableStream) => void;
25}
26
27export class LogHelper {
28public static get LOG_LEVEL(): LogLevel {
29return getLogLevel();
30}
31}
32
08722261Yuri Skorokhodov7 years ago33export interface DevLogToFileSettings {
34LogsDirectory: string | undefined;
35}
36
37export function getLoggingOptions(): DevLogToFileSettings {
38return {
39LogsDirectory: process.env.REACT_NATIVE_TOOLS_LOGS_DIR,
40};
41}
42/**
43* Returns directory in which the extension's log files will be saved
44* if `env` variables `REACT_NATIVE_TOOLS_LOGS_DIR` is defined.
45* Also, checks that path is a correct absolute path. Creates new folder if not exists yet.
46* @returns Path to the logs folder or null
47*/
48export function getLoggingDirectory(): string | null {
49const loggingOptions = getLoggingOptions();
50if (loggingOptions.LogsDirectory) {
51let dirPath = loggingOptions.LogsDirectory;
52if (!path.isAbsolute(dirPath)) {
53return null;
54}
55mkdirp.sync(dirPath);
56return dirPath;
57}
58return null;
59}
60
0a68f8dbArtem Egorov8 years ago61function getLogLevel() {
62try {
63const SettingsHelper = require("../settingsHelper").SettingsHelper;
64return SettingsHelper.getLogLevel();
65} catch (err) { // Debugger context
66return LogLevel.Info; // Default
67}
68}