Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ The following environment variables affect the behavior of Wireit:
| `CI` | Affects the default value of `WIREIT_CACHE`.<br><br>Automatically set to `true` by [GitHub Actions](https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables) and most other CI (continuous integration) services.<br><br>Must be exactly `true`. If unset or any other value, interpreted as `false`. |
| `WIREIT_MAX_OPEN_FILES` | Limits the number of file descriptors Wireit will have open concurrently. Prevents resource exhaustion when checking large numbers of cached files. Set to a lower number if you hit file descriptor limits. |
| `WIREIT_LOGGER` | How to present progress and results on the command line.<br><br>Options:<br><ul><li>`quiet` (default): writes a single dynamically updating line summarizing progress. Only passes along stdout and stderr from commands if there's a failure, or if the command is a service. The planned new default, please try it out.</li><li>`simple` (default): A verbose logger that presents clear information about the work that Wireit is doing.</li><li>`metrics`: Like `simple`, but also presents a summary table of results once a command is finished.</li><li>`quiet-ci` (default when env.CI or !stdout.isTTY): like `quiet` but optimized for non-interactive environments, like GitHub Actions runners.</li></ul> |
| `WIREIT_LOGGER_PREFIX` | When this env variable is present and not empty, Wireit will prefix each stdout and stderr line from the script with its name. |

### Glob patterns

Expand Down
17 changes: 14 additions & 3 deletions src/logging/default-logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import * as pathlib from 'path';
import {unreachable} from '../util/unreachable.js';

import type {Event} from '../event.js';
import type {Event, Stderr, Stdout} from '../event.js';
import type {Logger, Console} from './logger.js';
import {type PackageReference, type ScriptReference} from '../config.js';
import {DiagnosticPrinter} from '../error.js';
Expand Down Expand Up @@ -42,6 +42,8 @@ export class DefaultLogger implements Logger {
readonly console: Console;
readonly #diagnosticPrinter: DiagnosticPrinter;

private outputWrite: typeof DefaultLogger.prototype.outputWriteDebug;

/**
* @param rootPackage The npm package directory that the root script being
* executed belongs to.
Expand All @@ -50,6 +52,15 @@ export class DefaultLogger implements Logger {
this.#rootPackageDir = rootPackage;
this.#diagnosticPrinter = new DiagnosticPrinter(this.#rootPackageDir);
this.console = ourConsole;
this.outputWrite = process.env['WIREIT_LOGGER_PREFIX'] ? this.outputWriteDebug : this.outputWriteDefault;
}

private outputWriteDefault(this: void, stream: NodeJS.WritableStream, event: Stdout | Stderr) {
stream.write(event.data);
}

private outputWriteDebug(this: void, stream: NodeJS.WritableStream, event: Stdout | Stderr, label: string) {
stream.write(event.data.toString().split('\n').map(line => line.trim() ? `[${label}] ${line}` : line).join('\n'));
}

log(event: Event) {
Expand Down Expand Up @@ -222,11 +233,11 @@ export class DefaultLogger implements Logger {
// TODO(aomarks) More advanced handling of output streams so that
// output isn't simply interweaved.
case 'stdout': {
this.console.stdout.write(event.data);
this.outputWrite(this.console.stdout, event, label);
break;
}
case 'stderr': {
this.console.stderr.write(event.data);
this.outputWrite(this.console.stderr, event, label);
break;
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/logging/quiet/run-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,13 @@ export class QuietRunLogger implements Disposable {
return state.hasBufferedOutput;
}

private outputWrite = process.env['WIREIT_LOGGER_PREFIX'] ? (stream: NodeJS.WritableStream, output: Output) => {
const label = labelForScript(this.#rootPackage, output.script);
stream.write(output.data.toString().split('\n').map(line => line.trim() ? `[${label}] ${line}` : line).join('\n'));
} : (stream: NodeJS.WritableStream, output: Output) => {
stream.write(output.data);
}

#handleOutput(event: Output): StatusLineResult {
const key = scriptReferenceToString(event.script);
const state = this.#running.get(key);
Expand All @@ -618,9 +625,9 @@ export class QuietRunLogger implements Disposable {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
using _pause = this.#statusLineWriter.clearUntilDisposed();
if (event.stream === 'stdout') {
process.stdout.write(event.data);
this.outputWrite(process.stdout, event);
} else {
process.stderr.write(event.data);
this.outputWrite(process.stderr, event);
}
return noChange;
}
Expand Down