Closed linuswillner closed 3 months ago
Hi @linuswillner,
That makes sense.
I would suggest the following. Currently, the verbose
option can be 'none'
, 'short'
or 'full'
. We could allow it to be a function (line, verboseEvent) => string | undefined
instead.
The function maps the line
being logged.
If undefined
is returned, Execa does not log anything. This allows ignoring specific types of messages. This also allows logging to files or remotely instead of the console.
line
is the full verbose line string, as formatted by Execa.
verboseEvent
is the same information but as an object instead. It has the following fields:
type
{string}
among:
'command'
: when subprocess starts 'output'
: stdout/stderr output'ipc'
: IPC message'error'
: error message'duration'
: total duration when subprocess endsmessage
{string}
: serialized and split line-wise (each verboseEvent
is a single line)timestamp
{Date}
failed
{boolean}
: same as result.failed
piped
{boolean}
: same as result.pipedFrom.length > 0
escapedCommand
{string}
: same as result.escapedCommand
commandId
{bigint}
: command identifier, incremented from 0 options
{Options}
: subprocess optionsWhat are your thoughts on this @sindresorhus?
👍 Sounds quite flexible, which would enable multiple use-cases.
Update: I started working on it. :+1:
PR at #1130.
The verbose log function of this library is very handy, as it makes it possible to conveniently log even command runs passed in via template literal. Defining a wrapper function for those is a bit of a faff all said and told.
However, as might be expected, not everyone is using the same log format. That's the case for the project I'm working on, and I'd like the logs to be uniform. Would it be possible to add a way to customize the format used by the
verbose
parameter? I'd be more than happy with just passing in a function somewhere that can take the command that was just run as a parameter, format it however I need to, and return it to execa to be logged.