UNPKG

log-tags

Version:

Color tags for devtools console.log

19 lines (18 loc) 634 B
import { combineLogTags } from "./utils"; import { logTag } from "./logTag"; export function taggedLogger(text, options) { const { bg, style, logFn = console.log, tags = [] } = options ?? {}; const tag = logTag(text, style ?? bg); const combinedTags = combineLogTags(...tags, tag); const log = function (...args) { logFn.call(this, ...combinedTags, ...args); }; log.childLogger = (text, options) => { return taggedLogger(text, { ...options, logFn: options?.logFn ?? logFn, tags: [...(options?.tags ?? []), ...tags, tag], }); }; return log; }