diff --git a/README.md b/README.md index a7aa2e960a..e686e05bc4 100644 --- a/README.md +++ b/README.md @@ -359,6 +359,49 @@ outputs. Or use a CLI argument `--quiet` to set `$.verbose = false`. +### `$.logOutput` + +Specifies zx debug channel: `stdout/stderr`. Defaults to `stderr`. + +### `$.logFormat` + +Specifies zx log output formatter. Defaults to `identity`. + +```js +// Nice place to add masker, if you pass creds to zx methods +$.logFormat = (msg) => msg.map(m => m.toUpperCase()) +``` + +### `$.logIgnore` + +Specifies log events to filter out. Defaults to `''`, so everything is being logged. + +```js +$.logIgnore = ['cd', 'fetch'] +cd('/tmp/foo') +$.fetch('https://example.com') +// `$ cd /tmp/foo` is omitted +// `$ fetch https://example.com` is not printed too + +$.logIgnore = 'cmd' +$`echo 'test'` +// prints `test` w/o `$ echo 'test'` +``` + +### `$.logPrint` + +Specifies event logging stream. Defaults to `process.stdout/process.stderr`. + +```js +let stdout = '' +let stderr = '' + +$.logPrint = (data, err) => { + if (data) stdout += data + if (err) stderr += err +} +``` + ### `$.env` Specifies env map. Defaults to `process.env`. @@ -461,6 +504,18 @@ ctx(async ($) => { }) ``` +### `log()` + +The logger. Accepts config via `$.log*` options. + +```js +import {log} from 'zx/experimental' + +log({scope: 'foo', verbose: 1, output: 'stderr'}, 'some', 'data') +// some data +``` + + ## FAQ ### Passing env variables diff --git a/package.json b/package.json index ae9b467339..89429c5c44 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ "chalk": "^5.0.1", "fs-extra": "^10.1.0", "globby": "^13.1.1", + "ignore": "^5.2.0", "minimist": "^1.2.6", "node-fetch": "^3.2.4", "ps-tree": "^1.2.0", diff --git a/src/cli.ts b/src/cli.ts index 3f469d4d6c..a42181b9ca 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -25,7 +25,8 @@ import { randomId } from './util.js' import './globals.js' await (async function main() { - $.verbose = !argv.quiet + $.verbose = +(argv.verbose || argv.quiet ? 0 : $.verbose) + if (typeof argv.shell === 'string') { $.shell = argv.shell } @@ -220,7 +221,8 @@ function printUsage() { zx [options]