microsoft/vscode-react-native

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
1.4.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

src/extension/log/LogHelper.ts

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