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

@vanillas/console-logger

v1.0.1

Published

A wrapper around the native Console API but which supports top-down threshold (levels) based control

Downloads

7

Readme

Console Logger

A wrapper around the native Console API but which supports top-down threshold (levels) based control

Why?

The functionality in tools like this or other similar libraries out there are to allow you to silence logging statements in your application by a single config change (especially when you have your logging threshold level controlled by an environment variable, this is as easy as a re-deploy without any application code changes).

Why does this matter? Because you can leave logger statements in your application permanently, but not have to remove them when you're done debugging (therefore you can use them again in the future when you have to check production logs).

You control all of this functionality by simply changing the threshold level. That way you can operate at a normal "info" or "warn" level when things are going well, but when there's a problem you can toggle the overall level to something much lower, which activates all those low-level logger.trace or logger.debug statements - and redeploy your application with full logging enabled.

Logging events can be expensive for high-traffic applications, so being able to toggle verbose logging on/off with a single config value.

Installation

npm install @vanillas/console-logger

Usage

Try it out in the NodeJs shell either next to a node_modules/ directory where @vanillas/console-logger has been installed, or try using replem as a global NPM package so you can load any NPM package into a NodeJs shell.

$ replem @vanillas/console-logger:logger

Installed into REPL context:
 - @vanillas/[email protected] as logger

> logger.level
'info'
> logger.setLevel("trace")
> logger.trace("Some very verbose logging statement")
Some very verbose logging statement
> logger.setLevel("debug")
> logger.trace("Some very verbose logging statement")
> logger.debug("Some slightly less verbose logging statement")
Some slightly less verbose logging statement
> logger.setLevel("warn")
> logger.info("Normal stuff to log to stdout")
> logger.error("something broke"
something broke

The only thing happening in this example is writing normal logging statements but the ones below the current logger threshold level never show up.

A NodeJs shell is just a quick way to demonstrate functionality for a simple package like this one, but in a front-end or back-end JavaScript/TypeScript appliction you instead just import this package and use it in the same manner demonstrated in the shell.