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

log-ninja

v2.0.4

Published

Handles logging for different environments: development, staging & production.

Downloads

37

Readme

Log Ninja

Handles colourful logging to the console for different log levels without needing to put if statements and console logs throughout your code.

// No more of this:
if (process.env.NODE_ENV === 'development') { console.log('My log message.'); }

// Now we have this:
log.debug('My log message.');

Quick Start

At the top of your application entry point you need to initialise Log-Ninja with a log level, before you require any other files in your application:

const log = require('log-ninja').init('debug');

log.info('Some information...');

Then in any other files in your application you just require Log-Ninja again to get the already initialised version:

const log = require('log-ninja');

// Will be output because "warn" has a lower log level than "debug".
log.warn('A warning 😮');

// Will NOT be output because "verbose" has a higher log level than "debug".
log.verbose('Lots and lots of detail.');

Log Levels

Log-Ninja supports the following log levels:

| ID | Level | Function | |---------|--------|--------------------------------------| | fatal | 0 | log.fatal(string1, string2, ...) | | error | 1 | log.error(string1, string2, ...) | | warn | 2 | log.warn(string1, string2, ...) | | info | 3 | log.info(string1, string2, ...) | | debug | 4 | log.debug(string1, string2, ...) | | verbose | 5 | log.verbose(string1, string2, ...) | | silly | 6 | log.silly(string1, string2, ...) |

Each of the functions support multiple strings which will be concatenated together with spaces (the same way console.log() works).

Output All Logs

If you inintialise Log-Ninja like .init('verbose') or .init(6) then ALL logs will be output to the console.

Output Only Errors

If you inintialise Log-Ninja like .init('error') or .init(1) then only error and fatal logs will be output to the console.

Turn Off Colours

If you don't want colours to be output you can pass a second parameter to .init() like so:

const log = require('log-ninja').init('debug', {
	colours: false,
});

Other Handy Functions

Log-Ninja comes with a few other functions to make logging to the console a little bit easier:

| Function | Description | |------------------------------------------|-------------| | log.title(string1, string2, ...) | Outputs an important message in bold and underlined. | | log.important(string1, string2, ...) | Outputs an important information in bold. | | log.success(string1, string2, ...) | Outputs a success message. | | log.final(string1, string2, ...) | Outputs the final success message of an execution. | | log.json(object1, object2, ...objectN) | Outputs JSON pretty printed for every object provided. | | log.space() | Outputs a blank line. | | log.raw(aSingleString) | Outputs a single string to stdout without any colours and without a trailing line break. | | log.rawError(aSingleString) | Outputs a single string to stderr without any colours and without a trailing line break. | | log.box(status, message) | Outputs a status followed by a message. Valid statuses are "ok", "fail", "warn" and "info". |