npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ai-tools/console-monkey-patch

v0.0.1

Published

Control where all console methods write to, avoiding writing to the process stdout and stderr.

Downloads

71

Readme

Console Monkey Patch

[Overview]

A versatile logging utility for Node.js that lets you intercept, extend, or replace console methods for custom logging workflows.

  1. Bring Your Own Logger: Seamlessly monkey-patch popular logging libraries (e.g., native console, winston, pino) to redirect their outputs to in-memory logs (this.context.stdout/stderr). Perfect for environments like sandboxes where you need to capture and control all logging.

  2. Hook Mode: Enable hook mode to chain pre-processing functions before passing messages to your existing logging library. This allows you to extend functionality without replacing your original methods.

  3. In-Memory Logger: Don't have a logging library? No problem. Get a console-like interface with in-memory logging, leveraging this.context.stdout and stderr to store logs without printing them.

Ideal for sandboxed environments, custom log pipelines, or capturing logs without terminal output.


[Calling Conventions]

| Name | Function | Calling Signature | Can't Exist | hookMode | Local Log | Patch Type | |-----------------------------------------|-------------|---------------------------------------------|-----------------------------------------|----------|-----------|--------------------------| | Instantiation with context | constructor | (context) | No consoleInstanceClass | false | Yes | Full Replace | | Instantiation with console | constructor | (consoleInstanceClass, hookMode?) | No context | optional | No | Full Replace / Chained Hook (based on hookMode) | | Instantiation with context and console | constructor | (context, consoleInstanceClass, hookMode?) | N/A | optional | Yes | Full Replace / Chained Hook (based on hookMode) | | Patch with context | patch | (context, consoleInstanceClass?, hookMode?) | No patching without context | optional | Yes | Full Replace | | Patch with console | patch | (consoleInstanceClass, hookMode?) | No context | optional | No | Full Replace / Chained Hook (based on hookMode) |


[Rules to explore]

| Rule | Related To | |----------------------------------------------------------------------------------------------------------------|------------------------------------------------------| | Local logging to this.context.stderr and this.context.stdout require a context to be passed so they can log to the class locally | Instantiation with context, Instantiation with context and console, Patch with context | | If local logging is not needed (i.e., when the caller provides an external logging mechanism via a console instance or context functions), this.context.stdout and this.context.stderr should be explicitly set to null to avoid unnecessary duplication of logs in memory | Instantiation with console, Instantiation with context and console, Patch with console | | If both a context and an external logging library are provided but local logging is not required, this.context.stdout and stderr should be explicitly set to null to avoid log duplication | Instantiation with context and console, Patch with console | | When no external logging library is provided, the library should default to in-memory logging via this.context.stdout and stderr, ensuring both are initialized as non-null strings | Instantiation with context, Patch with context | | When hook mode is enabled, local logging (this.context.stdout and stderr) should be completely bypassed, with all logs processed only by the chained external logging method | Instantiation with console, Instantiation with context and console, Patch with console | | Ensure that in paths where external logging is used, no interaction occurs with this.context.stdout or stderr unless both context and external logging are required | Instantiation with console, Patch with console |