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 🙏

© 2026 – Pkg Stats / Ryan Hefner

console_wrapper

v1.0.5

Published

A console wrapper for typescript applications

Downloads

8

Readme

Requirements

This library will work with any typescript project such as:

  • nodeJS + typescript
  • Angular2 + typescript

Description

I saw in many projects developers who use console.log, console.warn, etc.. everywhere in their code. Then, they want to push their code to production servers. But oh!! The logs! They are spreaded everywhere in the code and they are useful. Using a new logger library to replace all these logs can be painful and somewhat cumbersome. So why not just wrapping all console by a logger, that would let the code untouched ? Well, this is exactly what this library does! :)

This library is a wrapper around console that allow to show the proper level of logs in the code without touching the console.x occurrences in your code and without having to write a logger and inject it in all functions that need some logging. Instantiate this code once will allow you to set the log level without touching your console.X methods in your code.

It keeps the line number of the original log.

Log level

The following rules is applied:

TRACE < DEBUG < INFO < WARN < ERROR

So setting the log level to "trace" will show all the detailed logs. But obviously, in production, you probably prefer to only show a "warn" or "error" level.

In a more graphic way, here is how the selection rule works. In the following table, the vertical header shows the level of the logging request, designated by p, while the horizontal header shows effective level of the logger, designated by q. The intersection of the rows (level request) and columns (effective level) is the boolean resulting from the basic selection rule. Levels

How to use

At the beginning of your program, call the following:

import { Logger } from 'console-logger'
new Logger({ level: 'trace' })

Available console methods

The following methods are wrapped:

  • trace
  • debug
  • info
  • warn
  • error
  • dir
  • log

Options

  • level: log level
  • callback: a function to execute before the log is output. It won't be executed if the log level is not high enough
  • forceCallback: force the callback to be executed even if the log level does not allow it

Examples

Basic logger with log filtering

Suppose you're in prod, you may want to disable all logs:

import { Logger } from 'console-logger'
new Logger({ level: 'off' })

Run additional logic when console methods are called

import { Logger } from 'console-logger'
const options = {
   level: 'off',
   info: {
       callback: function(){
	       // so something here
	   }
   },
   error: {
       callback: function(){
	       reportToCloud('blah', arguments); // send error to remote server
	   },
       forceCallback: true
   }
}
window.logger = new Logger(options)

Reload options

You can reload the logger without re-instantiating it:

logger = window.logger
logger.options.log.callback = function() {
    // do something
}
logger.reloadOptions()

Build

Run:

tsc index.ts

to generate index.js