# @link-intersystems/console-proxy

> Easy to use and flexible console redirection library.

Latest version **1.1.1** (published 2021-11-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install @link-intersystems/console-proxy
pnpm add @link-intersystems/console-proxy
yarn add @link-intersystems/console-proxy
bun add @link-intersystems/console-proxy
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2021-11-02 |
| First published | 2021-10-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 58.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | rene.link |
| Keywords | console, redirection |

## Links

- npm: https://www.npmjs.com/package/@link-intersystems/console-proxy
- Repository: https://github.com/link-intersystems/console-proxy
- Homepage: https://github.com/link-intersystems/console-proxy#readme
- Issues: https://github.com/link-intersystems/console-proxy/issues
- npm.io page: https://npm.io/package/@link-intersystems/console-proxy

## Recent versions

- 1.1.1 (latest) — 2021-11-02
- 1.1.0 — 2021-10-22
- 1.0.1 — 2021-10-22
- 1.0.0 — 2021-10-22

## README

# Console Proxy Library

![GitHub Workflow Status](https://img.shields.io/github/workflow/status/link-intersystems/console-proxy/Node.js%20CI)
![Coveralls](https://img.shields.io/coveralls/github/link-intersystems/console-proxy)
![GitHub issues](https://img.shields.io/github/issues-raw/link-intersystems/console-proxy)
[![GitHub](https://img.shields.io/github/license/link-intersystems/console-proxy?label=license)](LICENSE.md)

A library to intercept console function calls.

## Install

     npm i "@link-intersystems/console-proxy"

## Use

    import {
        createConsoleProxy,
        createConsoleTemplate,
        createLogEnablementInterceptor,
    } from "@link-intersystems/console-proxy";

    const logEnablement = createLogEnablementInterceptor();
    const consoleProxy = createConsoleProxy(console, logEnablement);

    logEnablement.setLevelEnabled("debug", false)


    consoleProxy.info("INFO", "Hello", "World");
    consoleProxy.debug("DEBUG", "Hellow", "World");     
    // Since debug is disabled only info is logged.
    // OUTPUT:
    // INFO Hello World

A consoleProxy does not change the default console. 
If you want to change the default console you can either use the [console template](src/template/README.md)

    function codeThatLogs() {
        console.log("Hello");
        console.info("World");
    }

    logEnablement.setLevelEnabled("info", false)

    consoleTemplate.execFn(codeThatLogs)
    // OUTPUT:
    // Hello

or manually enable/disable the [console proxy](src/proxy/README.md).

    const disableConsoleProxy = consoleProxy.enable();
    // The target console's functions will be redirected through the proxy.

    console.log("Hello", "World"); // is proxied

    disableConsoleProxy();
    // The target console's functions are restored.

    console.log("Hello", "World"); // is not proxied

## Console Template Module

The console template module provides template methods that ensure that the console is properly proxies when the target function executes. [Read more](src/template/README.md)

    logEnablementHandler.setLevelEnabled("info", false);
    consoleTemplate.execFn(codeThatLogs)

## Console Proxy Module

The consoleProxy module provides support for intercepting a console, usually the default console. [Read more](src/proxy/README.md)

    let lastInfoLog: string;

    const consoleProxy = createConsoleProxy();
    consoleProxy.setInterceptorFunction("info", (...args) => {
        lastInfoLog = args.join(" ");
    })

    consoleProxy.setInterceptorFunction("log", (...args) => {
        // log diabled
    })

## Console Proxy Interceptors

This module contains interceptors for the console proxy. [Read more](src/interceptors/README.md)

     const logEnablementInterceptor = createLogEnablementInterceptor();
     logEnablementInterceptor.setLevelEnabled("log", false);

     consoleProxy.setInterceptor(logEnablementInterceptor);

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