UNPKG

@boost/log

Version:

Lightweight level based logging system.

42 lines (39 loc) 1.08 kB
import os from 'node:os'; import { Contract } from '@boost/common'; import { LOG_LEVELS } from './constants.mjs'; import { debug } from './formats.mjs'; class Transport extends Contract { constructor(options) { super(options); this.levels = []; this.levels = this.options.levels; } blueprint(schemas) { const array = schemas.array, func = schemas.func, string = schemas.string; return { eol: string(os.EOL), format: func(), levels: array().of(string().oneOf(LOG_LEVELS)) }; } /** * Format the log item into a message string, and append a trailing newline if missing. */ format(item) { const _this$options = this.options, eol = _this$options.eol, format = _this$options.format; let output = typeof format === 'function' ? format(item) : debug(item); if (eol && !output.endsWith(eol)) { output += String(eol); } return output; } /** * Write the formatted message according to the transport. */ } export { Transport }; //# sourceMappingURL=Transport.mjs.map