UNPKG

@amplitude/ampli

Version:

Amplitude CLI

41 lines (40 loc) 1.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const fs = require("fs"); const debug_1 = require("debug"); const ansiRegex = require("ansi-regex"); class Debugger { constructor() { this.enable = (namespaces = 'itl*') => debug_1.default.enable(namespaces); this.debug = debug_1.default('ampli'); this.defaultLogMethod = console.log.bind(console); this.debug.log = this.log.bind(this); } log(...args) { let argStr = args.join(''); argStr = /[\r\n]*$/.test(argStr) ? argStr : `${argStr}\n`; if (this.logFilePath) { const output = argStr.replace(ansiRegex(), ''); fs.appendFileSync(this.logFilePath, output); } else { this.defaultLogMethod(argStr); } } extend(namespace, delimiter) { return this.debug.extend(namespace, delimiter); } logToFile(filepath) { this.logFilePath = filepath; } hasLogFile() { return this.logFilePath !== undefined; } getLogFilePath() { return this.logFilePath; } logToConsole() { this.logFilePath = undefined; } } exports.default = new Debugger();