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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@novice1/logger

v1.6.0

Published

Logging utility

Downloads

808

Readme

@novice1/logger

A JavaScript logging utility that prefixes logs and colors them if stdout/stderr is a TTY. Works in Node.js.

Installation

$ npm install @novice1/logger

Usage

Once imported use the function as it is or use its methods to log.

Example:

let logger = require('@novice1/logger');

// white
logger('simple log'); 
logger.log('simple log');

// blue
logger.info('info log');

// magenta background
logger.debug('debug log');

// yellow
logger.warn('yellow log');

// red
logger.error('error log');

You can also chose your own colors for the logs using the methods print and println. Available colors can be found in the property colors.

Example:

let logger = require('@novice1/logger');

// green
logger.print(logger.colors.FG_GREEN, 'green', 'message');

// blue background
logger.println(logger.colors.BG_BLUE, 'blue background', 'message');

Available colors

  • RESET
  • BRIGHT
  • DIM
  • UNDERSCORE
  • BLINK
  • REVERSE
  • HIDDEN
  • FG_BLACK
  • FG_RED
  • FG_GREEN
  • FG_YELLOW
  • FG_BLUE
  • FG_MAGENTA
  • FG_CYAN
  • FG_WHITE
  • BG_BLACK
  • BG_RED
  • BG_GREEN
  • BG_YELLOW
  • BG_BLUE
  • BG_MAGENTA
  • BG_CYAN
  • BG_WHITE

Methods

  • error: (...args: any[]) => void
  • warn: (...args: any[]) => void
  • info: (...args: any[]) => void
  • log: (...args: any[]) => void
  • debug: (...args: any[]) => void
  • silly: (...args: any[]) => void
  • println: (colorCode: int, ...args: any[]) => void
  • print: (colorCode: int, ...args: any[]) => void

Levels

Methods can print logs depending on the level of the logger. Levels are available in the property levels.

By priority:

  • error
  • warn
  • info
  • log / verbose
  • debug
  • silly

Example:

let logger = require('@novice1/logger');

// set level to info
logger.setLevel(logger.levels.info);

// will print
logger.info('info log');

// will print
logger.warn('warn log');

// will not print
logger.print(logger.colors.FG_GREEN, 'green', 'message');

Using with debug

It can be used with the package debug. All you have to do call the method debugger sending a namespace as parameter. That will return a function with the available methods except for print and println.

debug properties and methods are available from the property Debug.

Example:

// enable 'app:*'
require('@novice1/logger').Debug.enable('app:*');

let logger = require('@novice1/logger').debugger('app:log');
logger('simple log'); 
logger.log('simple log');
logger.info('info log');
logger.debug('debug log');
logger.warn('yellow log');
logger.error('error log');

You can also extend debugger

// enable 'auth:*'
require('@novice1/logger').Debug.enable('auth:*');

let logger = require('@novice1/logger').debugger('auth');

// extend namespace
const logSign = logger.extend('sign');
const logLogin = logger.extend('login');

logger('hello'); // auth log : hello
logSign('hello'); //auth:sign log : hello
logLogin('hello'); //auth:login log : hello

Formatters

printf-style formatting can be used when using with debug.

Officially supported formatters:

| Formatter | Representation | |-----------|----------------| | %O | Pretty-print an Object on multiple lines. | | %o | Pretty-print an Object all on a single line. | | %s | String. | | %d or %i | Number (both integer and float). | | %j | JSON. Replaced with the string '[Circular]' if the argument contains circular references. | | %% | Single percent sign ('%'). This does not consume an argument. |

Other formatters:

| Formatter | Representation | |-----------|----------------| | %P | Print an Object on multiple lines. | | %p | Print an Object on a single line. |

Custom logger

You can create a custom logger, assign its own level, print function (= write) and more.

Example:

const Logger = require('@novice1/logger');

// create custom logger
const customLogger = Logger.createLogger({
  levels: {
    success: {
      // color of message.
      color: Logger.colors.FG_GREEN, 
      // level. Default: Logger.levels.silly
      level: Logger.levels.info 
    }
  },
  /**
   * Overwrite the default function to print.
   * Could be used to customize message, write in a file, etc ...
   */
  write({ args, level, message, prefixText }) {
    console.log(`custom ${prefixText} - ${message} !`);
  }
});

// print objects on a single line
customLogger.singleLine = true;

// set level
customLogger.level = Logger.levels.log;

// will not print because of level set
customLogger.debug('debug log');

// will print
customLogger('simple log'); 
customLogger.log('simple log');
customLogger.info('info log');
customLogger.warn('warning log');
customLogger.error('error log');

// custom level print
customLogger.custom('success',  'everything is good');