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

that-logger

v1.0.7

Published

You might be thinking something like this while reading this:

Downloads

2

Readme

that-logger

You might be thinking something like this while reading this:

that-logger? Yet another logger with basic coloring functionality? Why do we need this?

On the surface? Perhaps there is some truth to that. But that-logger is an especially powerful and useful logger for one reason that we'll get to later.

Creating and using a logger.

First, we need to create our logger to log things... obviously.

import Logger from 'that-logger';

const log = new Logger();

Now... let's log something.

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

Internally, this gets converted to:

log.log('info', 'Some basic info.');

Which outputs something that looks like this:

INFO Some basic info.

The reason for this is that that-logger operates based on an extendable prefix system. For example, you could import prefixes from that-logger

import Logger, { prefixes } from 'that-logger';
import chalk from 'chalk'; //For coloring

Then, you can make a new logger with a new prefix.

const log = new Logger({
    prefixes: {
        ...prefixes,
        success: chalk.green('SUCCESS');
    }
});

Now, once we do log.log('success', msg), we'll have it prefixed with SUCCESS.

Here are the main logging methods:

Logger.info
Logger.warn
Logger.debug
Logger.error

Ignoring Debug Logs

Doing other things like ignoring specific log prefixes is as easy as pie too.

const log = new Logger({
    ignore: [ 'debug' ]
});

Sub-Loggers

There's a reason that-logger stands out, and that's sub-loggers. Let's make one ourselves:

const sub = log.create('Sub');

Now, sub is a new log with the same methods, like info, warn, even log. It's an instance of Logger, just like the main logger. However, when we try logging with it, with for example something like:

sub.info('Cool, cool cool cool, cool.');

We get the following output:

Sub
    INFO Cool, cool cool cool, cool.

And of course, sub also supports .create. With sub-loggers, you can easily organize your logs into neat packages which makes life easier.

Even better, you can handle errors much easier since it's super easy to see where the error came from.

If you want to learn more, read the source code, it's not too complex (other then the match function), and have a good time using that-logger!