Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@link-intersystems/console-proxy

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@link-intersystems/console-proxy

Easy to use and flexible console redirection library.

latest
Source
npmnpm
Version
1.1.1
Version published
Maintainers
1
Created
Source

Console Proxy Library

GitHub Workflow Status Coveralls GitHub issues GitHub

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

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

logEnablement.setLevelEnabled("info", false)

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

or manually enable/disable the console proxy.

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

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

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

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

 consoleProxy.setInterceptor(logEnablementInterceptor);

Keywords

console

FAQs

Package last updated on 02 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts