# patch-console

> Patch console methods to intercept output

Latest version **2.0.0** (published 2022-02-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install patch-console
pnpm add patch-console
yarn add patch-console
bun add patch-console
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2022-02-04 |
| First published | 2020-06-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | ^12.20.0 \|\| ^14.13.1 \|\| >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 5.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 19 |
| Author | vdemedes |
| Maintainers | vdemedes |
| Keywords | stdout, stderr, patch, console, intercept, log, logs |

## Links

- npm: https://www.npmjs.com/package/patch-console
- Repository: https://github.com/vadimdemedes/patch-console
- Homepage: https://github.com/vadimdemedes/patch-console#readme
- Issues: https://github.com/vadimdemedes/patch-console/issues
- npm.io page: https://npm.io/package/patch-console

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 2.0.0 (latest) — 2022-02-04
- 1.0.0 — 2020-06-15

## README

# patch-console ![test](https://github.com/vadimdemedes/patch-console/workflows/test/badge.svg)

> Patch console methods to intercept output

## Install

```
$ npm install patch-console
```

## Usage

```js
import patchConsole from 'patch-console';

const restore = patchConsole((stream, data) => {
	// stream = 'stdout'
	// data = "Hello World"
});

console.log('Hello World');

// Restore original methods
restore();
```

## API

### patchConsole(callback)

After this function is called, output from console methods will be intercepted and won't show up in the actual stdout or stderr stream.
To restore original console methods and stop intercepting output, call the function which `patchConsole()` returns.

#### callback

Type: `Function`

Function that will be called when output from one of the console methods is intercepted.
First argument is name of the stream (`"stdout"` or `"stderr"`), second argument is output itself.

## Console methods

This module intercepts the following methods:

- `console.assert()`
- `console.count()`
- `console.countReset()`
- `console.debug()`
- `console.dir()`
- `console.dirxml()`
- `console.error()`
- `console.group()`
- `console.groupCollapsed()`
- `console.groupEnd()`
- `console.info()`
- `console.log()`
- `console.table()`
- `console.time()`
- `console.timeEnd()`
- `console.timeLog()`
- `console.trace()`
- `console.warn()`

---
_Source: https://npm.io/package/patch-console · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
