diff --git a/react-packager/src/Logger/index.js b/react-packager/src/Logger/index.js index 159ff2e6..11bf72f4 100644 --- a/react-packager/src/Logger/index.js +++ b/react-packager/src/Logger/index.js @@ -89,40 +89,40 @@ function print( if (!PRINT_LOG_ENTRIES) { return logEntry; } + const { + log_entry_label: logEntryLabel, + action_phase: actionPhase, + duration_ms: duration, + } = logEntry; - const {log_entry_label, action_phase, duration_ms} = logEntry; const timeStamp = new Date().toLocaleString(); - const logEntryDataList = []; - let logEntryString, logEntryDataString; + let logEntryString; - for (let i = 0, len = printFields.length; i < len; i++) { - const field = printFields[i]; - const value = logEntry[field]; - if (value === undefined) { - continue; - } - logEntryDataList.push(`${field}: ${value.toString()}`); - } - - logEntryDataString = logEntryDataList.join(' | '); - - if (logEntryDataString) { - logEntryDataString = ` ${logEntryDataString}`; - } - - switch (action_phase) { + switch (actionPhase) { case 'start': - logEntryString = chalk.dim(`[${timeStamp}] ${log_entry_label}${logEntryDataString}`); + logEntryString = chalk.dim(`[${timeStamp}] ${logEntryLabel}`); break; case 'end': - logEntryString = chalk.dim(`[${timeStamp}] ${log_entry_label}${logEntryDataString}`) + - chalk.cyan(` (${+duration_ms}ms)`); + logEntryString = chalk.dim(`[${timeStamp}] ${logEntryLabel}`) + + chalk.cyan(` (${+duration}ms)`); break; default: - logEntryString = chalk.dim(`[${timeStamp}] ${log_entry_label}${logEntryDataString}`); + logEntryString = chalk.dim(`[${timeStamp}] ${logEntryLabel}`); break; } + if (printFields.length) { + const indent = ' '.repeat(timeStamp.length + 11); + + for (const field of printFields) { + const value = logEntry[field]; + if (value === undefined) { + continue; + } + logEntryString += chalk.dim(`\n${indent}${field}: ${value.toString()}`); + } + } + // eslint-disable-next-line no-console-disallow console.log(logEntryString);