Socket
Book a DemoInstallSign in
Socket

that-logger

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

that-logger

You might be thinking something like this while reading this:

latest
npmnpm
Version
1.0.7
Version published
Maintainers
1
Created
Source

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!

Keywords

log

FAQs

Package last updated on 28 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.