Skip to content

Allow overwriting Bun.stdout and Bun.stderr #14874

@TomasHubelbauer

Description

@TomasHubelbauer

What is the problem this feature would solve?

I have a piece of code where a method writes to the standard output using console.log and when a condition is met, it should instead write to a file.

I have no control over the implementation of the method, so I am looking for ways to redirect the console.log and console.error calls.

I tried doing this:

const file = Bun.file('file-name.ext');
Bun.stdout = file;
Bun.stderr = file;

method(); // Calls `console.log` inside

However the standard output and standard error streams remained the terminal-attached ones, the file was created, but remained empty.

What is the feature you are proposing to solve the problem?

Make Bun.stdout and Bun.stderr read-write and respect the overriden values when using these internally as sinks for console methods. (But this should probably also affect process.stdout and process.stderr maybe?

What alternatives have you considered?

No response

Metadata

Metadata

Assignees

Labels

bun.jsSomething to do with a Bun-specific APIenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions