@@ -4,6 +4,7 @@ import readline from 'node:readline'
44import colors from 'picocolors'
55import type { RollupError } from 'rollup'
66import type { ResolvedServerUrls } from './server'
7+ import { splitRE } from './utils'
78
89export type LogType = 'error' | 'warn' | 'info'
910export type LogLevel = LogType | 'silent'
@@ -63,6 +64,8 @@ function getTimeFormatter() {
6364 return timeFormatter
6465}
6566
67+ const MAX_LOG_CHAR = 5000
68+
6669export function createLogger (
6770 level : LogLevel = 'info' ,
6871 options : LoggerOptions = { } ,
@@ -78,7 +81,22 @@ export function createLogger(
7881 allowClearScreen && process . stdout . isTTY && ! process . env . CI
7982 const clear = canClearScreen ? clearScreen : ( ) => { }
8083
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 )
82100 if ( options . timestamp ) {
83101 const tag =
84102 type === 'info'
0 commit comments