UNPKG

@kadena/hardhat-chainweb

Version:
52 lines 1.66 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.COLOR_PALETTE = void 0; exports.logInfo = logInfo; exports.logError = logError; exports.streamLogger = streamLogger; const picocolors_1 = __importDefault(require("picocolors")); const util_1 = require("util"); exports.COLOR_PALETTE = [ 'cyan', 'yellow', 'magenta', 'blue', 'green', 'red', ]; const colorText = util_1.styleText || function styleText(color, text) { if (!picocolors_1.default[color]) { return text; } return picocolors_1.default[color](text); }; /* *************************************************************************** */ /* Logging */ // TODO: should we use a logging library like winston or pino or would that make // this code to opinionated? function logInfo(color, label, msg) { const prefixedLabel = `[hardhat ${label}]`; const styledLable = colorText(color, prefixedLabel); console.log(styledLable, msg); } function logError(color, label, msg) { const prefixedLabel = `[hardhat ${label}]`; const styledLable = colorText(color, prefixedLabel); console.error(styledLable, msg); } function streamLogger(stream, logFun) { let buffer = ''; stream.on('data', (data) => { const parts = (buffer + data).split(/\r?\n/); for (const line of parts.slice(0, -1)) { logFun(line); } buffer = parts.slice(-1).join(); }); return buffer; } //# sourceMappingURL=logger.js.map