|
| 1 | +/* eslint-disable no-console */ |
| 2 | +import * as chalk from 'chalk'; |
| 3 | + |
| 4 | +// This is nextjs's own logging formatting, vendored since it's not exported. See |
| 5 | +// https://github.com/vercel/next.js/blob/c3ceeb03abb1b262032bd96457e224497d3bbcef/packages/next/build/output/log.ts#L3-L11 |
| 6 | +// and |
| 7 | +// https://github.com/vercel/next.js/blob/de7aa2d6e486c40b8be95a1327639cbed75a8782/packages/next/lib/eslint/runLintCheck.ts#L321-L323. |
| 8 | + |
| 9 | +const prefixes = { |
| 10 | + wait: `${chalk.cyan('wait')} -`, |
| 11 | + error: `${chalk.red('error')} -`, |
| 12 | + warn: `${chalk.yellow('warn')} -`, |
| 13 | + ready: `${chalk.green('ready')} -`, |
| 14 | + info: `${chalk.cyan('info')} -`, |
| 15 | + event: `${chalk.magenta('event')} -`, |
| 16 | + trace: `${chalk.magenta('trace')} -`, |
| 17 | +}; |
| 18 | + |
| 19 | +export const formatAsCode = (str: string): string => chalk.bold.cyan(str); |
| 20 | + |
| 21 | +export const nextLogger: { |
| 22 | + [key: string]: (...message: unknown[]) => void; |
| 23 | +} = { |
| 24 | + wait: (...message) => console.log(prefixes.wait, ...message), |
| 25 | + error: (...message) => console.error(prefixes.error, ...message), |
| 26 | + warn: (...message) => console.warn(prefixes.warn, ...message), |
| 27 | + ready: (...message) => console.log(prefixes.ready, ...message), |
| 28 | + info: (...message) => console.log(prefixes.info, ...message), |
| 29 | + event: (...message) => console.log(prefixes.event, ...message), |
| 30 | + trace: (...message) => console.log(prefixes.trace, ...message), |
| 31 | +}; |
0 commit comments