log.js
This file
Path
lib/verbose/log.js
51 lines · 2.0 KiB · JavaScript
Last changed by
Fix `verbose` discarding IPC messages when its function throwsSindre Sorhusbefore adoptionb548d8b
History of this fileTake it
The walk stopped after 200 commits: lines older than 9f65b86 point at it.
Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
lines 1–2why, one step back1import {inspect} from 'node:util';2import {escapeLines} from '../arguments/escape.js';Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 3–4why, one step back3import {defaultVerboseFunction} from './default.js';4import {applyVerboseOnLines} from './custom.js';100% test coverage (#1018)ehmickybefore adoption9f65b86
line 5why, one step back5Do not write verbose logs synchronously (#1167)ehmickybefore adoptione3572d0
lines 6–13why, one step back6// This prints on stderr.7// If the subprocess prints on stdout and is using `stdout: 'inherit'`,8// there is a chance both writes will compete (introducing a race condition).9// This means their respective order is not deterministic.10// In particular, this means the verbose command lines might be after the start of the subprocess output.11// Using synchronous I/O does not solve this problem.12// However, this only seems to happen when the stdout/stderr target13// (e.g. a terminal) is being written to by many subprocesses at once, which is unlikely in real scenarios.Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 14–17why, one step back14export const verboseLog = ({type, verboseMessage, fdNumber, verboseInfo, result}) => {15 const verboseObject = getVerboseObject({type, result, verboseInfo});16 const printedLines = getPrintedLines(verboseMessage, verboseObject);17 const finalLines = applyVerboseOnLines(printedLines, verboseInfo, fdNumber);Do not write verbose logs synchronously (#1167)ehmickybefore adoptione3572d0
lines 18–20why, one step back18 if (finalLines !== '') {19 console.warn(finalLines.slice(0, -1));20 }100% test coverage (#1018)ehmickybefore adoption9f65b86
lines 21–22why, one step back21};22Require Node.js 22 (#1243)Sindre Sorhusbefore adoption04b4454
lines 23–35why, one step back23const getVerboseObject = ({type, result, verboseInfo}) => {24 const {escapedCommand, commandId, rawOptions} = verboseInfo;25 const {piped = false, ...options} = rawOptions;26 return {27 type,28 escapedCommand,29 commandId: `${commandId}`,30 timestamp: new Date(),31 piped,32 result,33 options,34 };35};100% test coverage (#1018)ehmickybefore adoption9f65b86
line 36why, one step back36Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
line 37why, one step back37const getPrintedLines = (verboseMessage, verboseObject) => verboseMessageRefactor `verbose` logic (#1126)ehmickybefore adoptionf9f1199
line 38why, one step back38 .split('\n')Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
line 39why, one step back39 .map(message => getPrintedLine({...verboseObject, message}));100% test coverage (#1018)ehmickybefore adoption9f65b86
line 40why, one step back40Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 41–44why, one step back41const getPrintedLine = verboseObject => {42 const verboseLine = defaultVerboseFunction(verboseObject);43 return {verboseLine, verboseObject};44};Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
line 45why, one step back45Fix `verbose` discarding IPC messages when its function throwsSindre Sorhusbefore adoptionb548d8b
lines 46–47why, one step back46// Serialize any type to a line string, for logging.47// Tabs are escaped by `escapeLines()`, like any other control character.Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
line 48why, one step back48export const serializeVerboseMessage = message => {Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
line 49why, one step back49 const messageString = typeof message === 'string' ? message : inspect(message);Fix `verbose` discarding IPC messages when its function throwsSindre Sorhusbefore adoptionb548d8b
line 50why, one step back50 return escapeLines(messageString);Log IPC messages with `verbose: 'full'` (#1063)ehmickybefore adoption839c2fe
line 51why, one step back51};