Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/11ty/_lib/chalk/README.md
Original file line number Diff line number Diff line change
@@ -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.
37 changes: 25 additions & 12 deletions packages/11ty/_lib/chalk/index.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Expand All @@ -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))
}

/**
Expand Down
5 changes: 3 additions & 2 deletions packages/11ty/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down