UNPKG

@case-contract-testing/case

Version:

Next-generation contract testing suite

54 lines (53 loc) 2.81 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeLogger = void 0; const chalk_1 = __importDefault(require("chalk")); const node_console_1 = require("node:console"); const caseVersion_1 = require("../../entities/caseVersion"); const shouldLog_1 = require("../../entities/logger/shouldLog"); const context_1 = require("../../entities/context"); const stdoutLogger = new node_console_1.Console({ stdout: process.stdout }); const caseVersionString = chalk_1.default.whiteBright(`(case@${caseVersion_1.caseVersion})`); const locationString = (context) => `${chalk_1.default.blueBright((0, context_1.locationString)(context))}`; const timestampString = () => new Date().toLocaleString(Intl.DateTimeFormat().resolvedOptions().locale, { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric', second: 'numeric', hourCycle: 'h24', timeZoneName: 'short', fractionalSecondDigits: 3, }); const makeLogger = (matchContext) => ({ warn(message, ...additional) { if ((0, shouldLog_1.shouldLog)(matchContext, 'warn')) { stdoutLogger.log(`${timestampString()} ${caseVersionString} ${chalk_1.default.yellowBright(`[WARNING]`)} ${locationString(matchContext)}: ${chalk_1.default.yellowBright(message)}`, ...additional); } }, error(message, ...additional) { if ((0, shouldLog_1.shouldLog)(matchContext, 'error')) { stdoutLogger.log(`${timestampString()} ${caseVersionString} ${chalk_1.default.redBright(`[ERROR]`)} ${locationString(matchContext)}: ${chalk_1.default.redBright(message)}`, ...additional); } }, debug(message, ...additional) { if ((0, shouldLog_1.shouldLog)(matchContext, 'debug')) { stdoutLogger.log(`${timestampString()} ${caseVersionString} ${chalk_1.default.cyan(`[DEBUG]`)} ${locationString(matchContext)}: ${message}`, ...additional); } }, maintainerDebug(message, ...additional) { if ((0, shouldLog_1.shouldLog)(matchContext, 'maintainerDebug')) { stdoutLogger.log(`${timestampString()} ${caseVersionString} ${chalk_1.default.bgBlueBright.black(`[MAINTAINER-DEBUG]`)} ${locationString(matchContext)}: ${message}`, ...additional); } }, deepMaintainerDebug(message, ...additional) { if ((0, shouldLog_1.shouldLog)(matchContext, 'deepMaintainerDebug')) { stdoutLogger.log(`${timestampString()} ${caseVersionString} ${chalk_1.default.bgMagentaBright.black(`[DEEP-MAINTAINER-DEBUG]`)} ${locationString(matchContext)}: ${message}`, ...additional); } }, }); exports.makeLogger = makeLogger;