Skip to content

Commit 2c6d952

Browse files
committed
add nextLogger
1 parent defc63e commit 2c6d952

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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

Comments
 (0)