UNPKG

@forzalabs/remora

Version:

A powerful CLI tool for seamless data translation.

71 lines (70 loc) 2.53 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = require("fs"); const path_1 = __importDefault(require("path")); class LocalLogService { constructor() { this.id = 'DevelopmentLogService'; this._folder = 'local_logs'; this._file = 'logs.txt'; this._path = path_1.default.join(this._folder, this._file); this.init = () => { if (!(0, fs_1.existsSync)(this._folder)) (0, fs_1.mkdirSync)(this._folder); return null; }; this.log = (text) => { try { console.log(text); this._write(text, 'LOG'); } catch (error) { console.error('ERROR on log', error); } finally { return null; } }; this.info = (text) => { try { console.info(text); this._write(text, 'INFO'); } catch (error) { console.error('ERROR on info', error); } finally { return null; } }; this.error = (error) => { try { console.error(error); this._write(error.message, 'INFO', error.name, error.stack); } catch (error) { console.error('ERROR on error', error); } finally { return null; } }; this._write = (text, level, errName, stackTrace) => { if (!text || text.length === 0) return; const date = '"' + new Date().toJSON() + '"'; const sanitizedLevel = '"' + level + '"'; const sanitizedText = '"' + text.replace(new RegExp('"', 'g'), '"') + '"'; const sanitizedErrName = '"' + (errName !== null && errName !== void 0 ? errName : '') + '"'; const sanitizedStack = '"' + (stackTrace !== null && stackTrace !== void 0 ? stackTrace : '') + '"'; const line = [date, sanitizedLevel, sanitizedText, sanitizedErrName, sanitizedStack]; const sanitizedLine = line.join(',') + '\r\n'; (0, fs_1.appendFileSync)(this._path, sanitizedLine); }; } } const LocalLogger = new LocalLogService(); exports.default = LocalLogger;