@@ -4,6 +4,7 @@ import readline from 'node:readline'
4
4
import colors from 'picocolors'
5
5
import type { RollupError } from 'rollup'
6
6
import type { ResolvedServerUrls } from './server'
7
+ import { splitRE } from './utils'
7
8
8
9
export type LogType = 'error' | 'warn' | 'info'
9
10
export type LogLevel = LogType | 'silent'
@@ -63,6 +64,8 @@ function getTimeFormatter() {
63
64
return timeFormatter
64
65
}
65
66
67
+ const MAX_LOG_CHAR = 5000
68
+
66
69
export function createLogger (
67
70
level : LogLevel = 'info' ,
68
71
options : LoggerOptions = { } ,
@@ -78,7 +81,22 @@ export function createLogger(
78
81
allowClearScreen && process . stdout . isTTY && ! process . env . CI
79
82
const clear = canClearScreen ? clearScreen : ( ) => { }
80
83
81
- function format ( type : LogType , msg : string , options : LogErrorOptions = { } ) {
84
+ function preventOverflow ( msg : string ) {
85
+ if ( msg . length > MAX_LOG_CHAR ) {
86
+ const shorten = msg . slice ( 0 , MAX_LOG_CHAR )
87
+ const lines = msg . slice ( MAX_LOG_CHAR ) . match ( splitRE ) ?. length || 0
88
+
89
+ return `${ shorten } \n... and ${ lines } lines more`
90
+ }
91
+ return msg
92
+ }
93
+
94
+ function format (
95
+ type : LogType ,
96
+ rawMsg : string ,
97
+ options : LogErrorOptions = { } ,
98
+ ) {
99
+ const msg = preventOverflow ( rawMsg )
82
100
if ( options . timestamp ) {
83
101
const tag =
84
102
type === 'info'
0 commit comments