Skip to content

Commit 8cca297

Browse files
committed
Use btr logging in console output
1 parent 747d0f7 commit 8cca297

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/logger.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,49 @@ ${logSymbols.error} errors: ${stats.errors.length}
9090
${logSymbols.warning} warnings: ${stats.warnings.length}
9191
${errors}${warnings}
9292
${chunkAndAssetLog}
93+
${buildBtrLog(stats)}
9394
${chalk.yellow(`output at: ${chalk.cyan(chalk.underline(`file:///${outputPath}`))}`)}
9495
9596
${signOff}
9697
`);
9798
return !!errors;
9899
}
100+
101+
function buildBtrLog(stats: any) {
102+
const btrLogs: string[] =
103+
stats &&
104+
stats.logging &&
105+
stats.logging.BuildTimeRender &&
106+
stats.logging.BuildTimeRender.entries
107+
.filter(({ type }: { type: string }) => type === 'info')
108+
.map(({ message }: { message: string }) => message);
109+
110+
const pagesVisited = btrLogs
111+
.filter((message) => message.startsWith('Visited:'))
112+
.map((message) => message.split('Visited:')[1]);
113+
const pagesDiscovered = btrLogs
114+
.filter((message) => message.startsWith('Discovered:'))
115+
.map((message) => message.split('Discovered:')[1]);
116+
const slowPages = btrLogs
117+
.filter((message) => message.startsWith('Slow:'))
118+
.map((message) => message.split('Slow:')[1].split(':Took:'));
119+
120+
let logs = '';
121+
if (pagesVisited.length) {
122+
logs += `Visited the following pages during BTR:\n${pagesVisited.map((page) => `${page}`).join('\n')}\n\n\n`;
123+
}
124+
125+
if (pagesDiscovered.length) {
126+
logs += `Discovered the following pages during BTR:\n${pagesDiscovered
127+
.map((page) => `${page}`)
128+
.join('\n')}\n\n\n`;
129+
}
130+
131+
if (slowPages.length) {
132+
logs += `These modules were slow to render during BTR:\n${slowPages
133+
.map(([page, time]) => `${page} took ${time} seconds`)
134+
.join('\n')}\n\n\n`;
135+
}
136+
137+
return logs;
138+
}

0 commit comments

Comments
 (0)