values.js
This file
Path
lib/verbose/values.js
33 lines · 1.6 KiB · JavaScript
Last changed by
Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
History of this fileTake it
Allow `verbose` option to be a function for custom logging (#1130)ehmickybefore adoption8daf348
lines 1–33why, one step back1import {getFdSpecificValue} from '../arguments/specific.js';23// The `verbose` option can have different values for `stdout`/`stderr`4export const isVerbose = ({verbose}, fdNumber) => getFdVerbose(verbose, fdNumber) !== 'none';56// Whether IPC and output and logged7export const isFullVerbose = ({verbose}, fdNumber) => !['none', 'short'].includes(getFdVerbose(verbose, fdNumber));89// The `verbose` option can be a function to customize logging10export const getVerboseFunction = ({verbose}, fdNumber) => {11 const fdVerbose = getFdVerbose(verbose, fdNumber);12 return isVerboseFunction(fdVerbose) ? fdVerbose : undefined;13};1415// When using `verbose: {stdout, stderr, fd3, ipc}`:16// - `verbose.stdout|stderr|fd3` is used for 'output'17// - `verbose.ipc` is only used for 'ipc'18// - highest `verbose.*` value is used for 'command', 'error' and 'duration'19const getFdVerbose = (verbose, fdNumber) => fdNumber === undefined20 ? getFdGenericVerbose(verbose)21 : getFdSpecificValue(verbose, fdNumber);2223// When using `verbose: {stdout, stderr, fd3, ipc}` and logging is not specific to a file descriptor.24// We then use the highest `verbose.*` value, using the following order:25// - function > 'full' > 'short' > 'none'26// - if several functions are defined: stdout > stderr > fd3 > ipc27const getFdGenericVerbose = verbose => verbose.find(fdVerbose => isVerboseFunction(fdVerbose))28 ?? VERBOSE_VALUES.findLast(fdVerbose => verbose.includes(fdVerbose));2930// Whether the `verbose` option is customized using a function31export const isVerboseFunction = fdVerbose => typeof fdVerbose === 'function';3233export const VERBOSE_VALUES = ['none', 'short', 'full'];