sindresorhus / execa

Process execution for humans
MIT License
6.79k stars 214 forks source link

Feature request: Possibility to use a custom verbose log format? #1124

Closed linuswillner closed 3 months ago

linuswillner commented 3 months ago

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.

ehmicky commented 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:

What are your thoughts on this @sindresorhus?

sindresorhus commented 3 months ago

👍 Sounds quite flexible, which would enable multiple use-cases.

ehmicky commented 3 months ago

Update: I started working on it. :+1:

ehmicky commented 3 months ago

PR at #1130.

ehmicky commented 3 months ago

This was released in 9.3.0. It is documented here and there.