UNPKG

excel2json

Version:
78 lines (77 loc) 2.88 kB
"use strict"; /** * @fileOverview logger * @name logger * @author Yuhei Aihara * https://github.com/iyu/excel2json */ /* eslint no-console:off */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const path_1 = __importDefault(require("path")); class OriginalLogger { constructor() { this.COLOR = { BLACK: '\u001b[30m', RED: '\u001b[31m', GREEN: '\u001b[32m', YELLOW: '\u001b[33m', BLUE: '\u001b[34m', MAGENTA: '\u001b[35m', CYAN: '\u001b[36m', WHITE: '\u001b[37m', RESET: '\u001b[0m', }; } _getDateLine() { const date = new Date(); const year = date.getFullYear(); let month = date.getMonth() + 1; month = month > 10 ? month : `0${month}`; let day = date.getDate(); day = day > 10 ? day : `0${day}`; const time = date.toLocaleTimeString(); return `[${year}-${month}-${day} ${time}]`; } _prepareStackTrace(err, stack) { const stackLine = stack[1]; const filename = path_1.default.relative('./', stackLine.getFileName()); return `(${filename}:${stackLine.getLineNumber()})`; } _getFileLineNumber() { const obj = {}; const original = Error.prepareStackTrace; Error.prepareStackTrace = this._prepareStackTrace; Error.captureStackTrace(obj, this._getFileLineNumber); const { stack } = obj; Error.prepareStackTrace = original; return stack; } info(...args) { Array.prototype.unshift.call(args, this.COLOR.RESET); Array.prototype.unshift.call(args, '[INFO]'); Array.prototype.unshift.call(args, this._getDateLine()); Array.prototype.unshift.call(args, this.COLOR.GREEN); Array.prototype.push.call(args, this._getFileLineNumber()); console.info.call(null, ...args); } debug(...args) { Array.prototype.unshift.call(args, this.COLOR.RESET); Array.prototype.unshift.call(args, '[DEBUG]'); Array.prototype.unshift.call(args, this._getDateLine()); Array.prototype.unshift.call(args, this.COLOR.BLUE); Array.prototype.push.call(args, this._getFileLineNumber()); console.log.call(null, ...args); } error(...args) { Array.prototype.unshift.call(args, this.COLOR.RESET); Array.prototype.unshift.call(args, '[ERROR]'); Array.prototype.unshift.call(args, this._getDateLine()); Array.prototype.unshift.call(args, this.COLOR.RED); Array.prototype.push.call(args, this._getFileLineNumber()); console.error.call(null, ...args); } } exports.default = new OriginalLogger();