mirror of
https://github.com/hanzoai/lint-staged.git
synced 2026-10-30 19:37:36 +00:00
26 lines
630 B
JavaScript
26 lines
630 B
JavaScript
import { formatWithOptions } from 'node:util'
|
|
|
|
import { COLORS_ENABLED, dim } from './colors.js'
|
|
|
|
const format = (...args) => formatWithOptions({ colors: COLORS_ENABLED }, ...args)
|
|
|
|
let activeLogger
|
|
|
|
export const enableDebug = (logger = console) => {
|
|
activeLogger = logger
|
|
}
|
|
|
|
/** @param {string} name */
|
|
export const createDebug = (name) => {
|
|
let previous = process.hrtime.bigint()
|
|
|
|
return (...args) => {
|
|
if (!activeLogger) return
|
|
|
|
const now = process.hrtime.bigint()
|
|
const ms = (now - previous) / 1_000_000n
|
|
previous = now
|
|
activeLogger.debug(dim(name + ': ') + format(...args) + dim(` +${ms}ms`))
|
|
}
|
|
}
|