UNPKG

@microsearch/lightning

Version:

Lightning fast text search for Node.js - blazing fast markdown and text search engine ⚡

45 lines 1.42 kB
import chalk from 'chalk'; import config from '../config/index.js'; function getTimestamp() { const now = new Date(); const options = { timeZone: config.TIMEZONE, hour12: false, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', fractionalSecondDigits: 3, }; return now.toLocaleString('en-US', options); } function formatMessage(module, message, level = 'info') { const timestamp = getTimestamp(); const moduleTag = chalk.cyan(`[${module}]`); const levelColor = { info: chalk.blue, warn: chalk.yellow, error: chalk.red, debug: chalk.gray, }[level]; return `${chalk.gray(timestamp)} ${moduleTag} ${levelColor(message)}`; } export function info(module, ...messages) { if (!config.VERBOSE && module === 'debug') return; console.log(formatMessage(module, messages.join(' '), 'info')); } export function warn(module, ...messages) { console.warn(formatMessage(module, messages.join(' '), 'warn')); } export function error(module, ...messages) { console.error(formatMessage(module, messages.join(' '), 'error')); } export function debug(module, ...messages) { if (!config.VERBOSE) return; console.debug(formatMessage(module, messages.join(' '), 'debug')); } //# sourceMappingURL=index.js.map