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-prefixer

v1.0.3

Published

Console with styled prefixes preserving correct line number

Readme

console-prefixer

Easily add styled prefixes to your logs with the lightweight (<1KB) console wrapper for ES5 supported Browsers or Node which also preserves the correct line numbers.

alt text

Features

  • Adjust log levels (For example to disable logs on production)
  • Set your own styled prefix per method
  • Preserves the correct line number in the debug console (This I really missed in most other loggers)
  • Create multiple loggers with different settings (global or local)
  • Types included

Installation

npm i console-prefixer --save

Usage

import {consolePrefixer} from 'console-prefixer' //or const {consolePrefixer} = require('console-prefixer')
const logger = consolePrefixer({
    defaultPrefix:{
        text:'my package \u2714',
        style:'background: green; color: white;font-weight:bold; padding:2px; border-radius:2px;'
    },
});

logger.log('Hey there!');

Will output (Chrome): alt text

Log Methods

  • debug
  • log
  • dir
  • group
  • groupCollapsed
  • groupEnd
  • trace
  • info
  • warn
  • error

All methods work exactly the same as it would with the console.

Other Methods

  • setOptions(options) -> new options
  • getOptions() -> options

To change the options you can either recall consolePrefixer or alter it with the setOptions method

Options

Options are set with consolePrefixer(options) or you can change it at anytime with setOptions

  • defaultPrefix
  • prefixes
  • logLevel

defaultPrefix

All methods except 'groupEnd' will include the prefix.

prefixes

You can also add method specific prefixes as follows:

import {consolePrefixer} from 'console-prefixer'

const logger = consolePrefixer({
   prefixes: {
       log: {
           text: 'CL',
           style: 'background: #3270A0; color: white;font-weight:bold; padding:2px; border-radius:20px; border: 1px solid white;'
       },
       info: {
           text: '\u2757'
       }
   }
});
  
logger.debug('debugging!'); //no prefix because no debug prefix or defaultPrefix is set
logger.log('logging list!', ['apple', 'pineapple']);
logger.info('Here some info');

Will output (Chrome): alt text

If a method doesnt have a specific prefix, defaultPrefix will be used. If there is also no defaultPrefix, no prefix will be used for this method.

logLevel

import {consolePrefixer} from 'console-prefixer'
const logger = consolePrefixer({
    defaultPrefix:{
        text:'my package \u2714',
        style:'background: green; color: white;font-weight:bold; padding:2px; border-radius:2px;'
    },
    logLevel: 2,
});
   
//will not show
logger.log('Hey there!');

//Show all logs again, handy if you want to show or hide logs at runtime
logger.setOptions({
     logLevel: 0,
})

//will show again
logger.log('Where were you!');

Ajust log level. Everything lower will not being shown:

  • 0 debug (default)
  • 1 log, dir, log, group, groupCollapsed, trace
  • 2 info
  • 3 warn
  • 4 error
  • 5 disable all

Usage inside your codebase

Use a logger anywhere

You don't want to setup a logger every time so make it accessible

Using window (browser only)

window.logger = consolePrefixer(my_options);
//any other file
logger.log('test')

Using module

//debug.js
export const logger = consolePrefixer(my_options);
//any other file
import {logger} from './debug'
logger.log('test')

Multiple loggers

You can create loggers anywhere. This can become in handy when you want to enable or disabled logs for a particular class or module. Or when you want different prefixes for different parts of the codebase.

Troubleshooting

Styling not working?

Not all browser or terminals support css styled logs. You might need to use another browser or download a plugin in case of Node.