dashersupply/src/apps/catalog/common/console.ts

9 lines
653 B
TypeScript

/**
* Returns a log function which upon calling will prepend the name of the command to the output. You can specify
* any log function, or if you don't specify one it will choose `console.log`.
* @param commandName Name of command to prepend in the logs.
* @param logFn The log function. If you don't provide a log function, it will automatically choose `console.log`.
* @returns A log function which upon calling it will prepend the command name to each output line.
*/
export const logForCommand = (commandName: string, logFn: ((...args: any[]) => void) = console.log) =>
(...args: any[]) => logFn.apply(null, [`[${commandName}]`, ...args]);