UNPKG

commanding

Version:

A simple yet practical command-Line application framework, written in TypeScript.

43 lines (42 loc) 1.5 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const chalk_1 = __importDefault(require("chalk")); const constant_1 = require("./constant"); class NotFancyLogger { constructor(level, colorEnabled = true, standardOutput = process.stdout, errorOutput = process.stderr) { this.level = level; this.colorEnabled = colorEnabled; this.standardOutput = standardOutput; this.errorOutput = errorOutput; } setLevel(level) { this.level = level; } setColor(enabled) { this.colorEnabled = enabled; } write(level, message, colorFunc) { if (level < this.level) { return; } let target = level < constant_1.LogLevel.ERROR ? this.standardOutput : this.errorOutput; const content = this.colorEnabled ? colorFunc(message) : message; target.write(content); } debug(message) { this.write(constant_1.LogLevel.DEBUG, message, chalk_1.default.bgCyan); } info(message) { this.write(constant_1.LogLevel.INFO, message, chalk_1.default.blue); } warn(message) { this.write(constant_1.LogLevel.WARN, message, chalk_1.default.bgYellow); } error(message) { this.write(constant_1.LogLevel.ERROR, message, chalk_1.default.bgRed); } } exports.NotFancyLogger = NotFancyLogger;