UNPKG

uzen

Version:

General-purpose GraphQL subscription server library

35 lines (34 loc) 946 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const colors = { reset: 0, red: 31, green: 32, yellow: 33, blue: 34, magenta: 35, cyan: 36, white: 37, }; function colorizeText(text, colorCode) { return `\x1b[${colorCode}m${text}\x1b[0m`; } class TimeLogger { startTimes; constructor() { this.startTimes = new Map(); } start(label) { this.startTimes.set(label, process.hrtime()); } logTime(label) { const startTime = this.startTimes.get(label); if (!startTime) { console.warn(`No start time found for label: ${label}`); return; } const endTime = process.hrtime(startTime); console.log(`${colorizeText(label, colors.cyan)}: ${colorizeText(`${endTime[0]}s`, colors.green)} ${colorizeText(`${endTime[1] / 1000000}ms`, colors.yellow)}`); } } exports.default = new TimeLogger();