diff --git a/packages/11ty/_lib/chalk/README.md b/packages/11ty/_lib/chalk/README.md index 3ee563740..319bff3d9 100644 --- a/packages/11ty/_lib/chalk/README.md +++ b/packages/11ty/_lib/chalk/README.md @@ -1,5 +1,7 @@ ## A façade module for the `chalk` library -A logging concern for Quire/11ty implemented using [loglevel](https://github.com/pimterry/loglevel) and [chalk](https://github.com/chalk/). +A logging concern for Quire/11ty implemented using [debug.js](https://github.com/debug-js/debug) and [chalk](https://github.com/chalk/). -Nota bene: `chalk` v5 is an ESM only library, Eleventy uses v4. For more information see the [chalk v4 documentation](https://github.com/chalk/chalk/tree/v4.1.2). +Log lines are in the format: `[quire] component:subComponent LEVEL ...message...`. + +Log level selection responds to globs on the `DEBUG` environment variable as it does for [11ty]() so `cross-env DEBUG='Eleventy*,*quire*' eleventy` will turn on logging for Eleventy itself and for quire while `cross-env DEBUG='*quire*' eleventy` will emit logs for only quire. \ No newline at end of file diff --git a/packages/11ty/_lib/chalk/index.js b/packages/11ty/_lib/chalk/index.js index bba7f3673..f4c127e5d 100644 --- a/packages/11ty/_lib/chalk/index.js +++ b/packages/11ty/_lib/chalk/index.js @@ -1,8 +1,8 @@ import chalk from 'chalk' -import log from 'loglevel' +import debug from 'debug' /** - * A factory function for custom logging methods using loglevel and chalk + * A factory function for custom logging methods using debug and chalk * * @typedef Loglevel {Number|String} A numeric index or case-insensitive name * [0]: 'trace' @@ -18,13 +18,6 @@ import log from 'loglevel' * @return {Object} Logger with methods `debug`, error`, `info`, `trace` ,`warn` */ export default function (prefix = '', loglevel = 2) { - /** - * Get a new logger object and set logging level (non-persistent) - * @see https://github.com/pimterry/loglevel - */ - const logger = log.getLogger(prefix) - logger.setLevel(loglevel, false) - /** * chalk themes * @see https://www.w3.org/wiki/CSS/Properties/color/keywords @@ -38,11 +31,31 @@ export default function (prefix = '', loglevel = 2) { warn: chalk.inverse.yellow } + /** + * Initialize loggers for each loglevel. + * + * NB: colors are manually disabled to use color-per-loglevel styling + * + * @see https://github.com/debug-js/debug + */ + prefix = prefix.padEnd(30, '\u0020') + + const loggers = { + debug: debug(styles.debug(`Quire:${prefix} ${chalk.bold('DEBUG')}\t`)), + error: debug(styles.error(`Quire:${prefix} ${chalk.bold('ERROR')}\t`)), + info: debug(styles.info(`Quire:${prefix} ${chalk.bold('INFO')}\t`)), + trace: debug(styles.trace(`Quire:${prefix} ${chalk.bold('TRACE')}\t`)), + warn: debug(styles.warn(`Quire:${prefix} ${chalk.bold('WARN')}\t`)) + } + + Object.entries(loggers).forEach(([logLevel, logger]) => { + logger.useColors = false + }) + const logFn = (type) => { - const log = logger[type] + const logger = loggers[type] const style = styles[type] - prefix = prefix.padEnd(30, '\u0020') - return (message) => log(style(chalk.bold(`[quire] ${type.toUpperCase()}\t`), `${prefix}`, message)) + return (message) => logger(style(message)) } /** diff --git a/packages/11ty/package.json b/packages/11ty/package.json index aab03fac6..2a67b7348 100644 --- a/packages/11ty/package.json +++ b/packages/11ty/package.json @@ -25,9 +25,10 @@ "main": ".eleventy.js", "scripts": { "benchmark": "cross-env DEBUG=Eleventy:Benchmark* eleventy", - "build": "cross-env ELEVENTY_ENV=production eleventy", + "build": "cross-env ELEVENTY_ENV=production DEBUG=\"\" eleventy", "clean": "del-cli _epub _site public", - "debug": "cross-env DEBUG=Eleventy* eleventy --dryrun", + "debug": "cross-env DEBUG='Eleventy*,*quire*' eleventy --dryrun", + "debug:quire": "cross-env DEBUG='*quire*' eleventy --dryrun", "dev": "cross-env ELEVENTY_ENV=development eleventy --serve", "lint": "eslint .", "lint:debug": "eslint . --debug",