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

v1.3.1

Published

A npm package to log information with your logs.

Downloads

3

Readme

log-info

Handy for info logging!

Install

Npm:

npm install log-info

Yarn:

yarn add log-info

Usage

Add this to your script:

require('log-info');

And if you now run this:

require('log-info');

console.log('I\'m using log-info!')

You should see something like this:

Output of example above.

It also works with clusters:

const numCPUs = require('os').cpus().length;
const cluster = require('cluster');

require('log-info');

if (cluster.isMaster) {

    console.log('Log from %s!', 'master');
    console.info('Info from %s!', 'master');
    console.warn('Warn from %s!', 'master');
    console.error('Error from %s!', 'master');
    console.debug('Debug from %s!', 'master');

    for (var i = 0; i < numCPUs; i++) {
        cluster.fork();
    }

} else {

    console.log('Log from %s!', 'cluster');

}

Should look something like this:

Output of example above.

Colors

You can add colors to your console.log's now, the syntax is as follows:

[<color | hex color> <text>]

Example:

require('log-info');

console.log('[blue This text should be blue.]')

console.log('[#00ff00 This text should be a bright %s.]', 'green')

console.log('[cyan There should be] [#ff0000 multiple colors] in this text.')

You should see something like this:

Output of example above.

If your console does not support more than 256 colors, you can not use hex colors, just the colors below:

All available colors

Options

You can configure some options to customize the output to your likings.

Options.time

Can be set to one of the following:

  • normal - Gives the standard time output, e.g. 26-03-2019 15:42:23.463. (default value)
  • iso - Gives the time in ISO format, e.g. 2019-03-26T14:42:23.463Z
  • none - Gives no time output.

Example:

require('log-info')({
    time: 'none'
});

console.log('A log whitout time!');

Will result in:

Output of the example above.

Options.pid

Can be set to the following:

  • true - Adds the pid of the process after the time. If it is the master process, it will be colored purple. (default value)
  • false - Rremoves the pid of the output.

Example:

require('log-info')({
    pid: false
});

console.log('A log whitout pid!');

Will result in:

Output of the example above.

Options.info

Can be set to the following:

  • true - Will add the type of log (info (green), warn (yellow), error (red) or debug (blue)) after the pid. (default value)
  • false - Will remove the info from the output.

Example:

require('log-info')({
    info: false
});

console.log('A log whitout info!');

Will result in:

Output of the example above.

Options.newline

Can be set to the following:

  • true - Adds a return (newline) after all the info. (default value)
  • false - Does not add a return (newline) after all the info
require('log-info')({
    newline: false
});

console.log('A log without a newline!');

Will result in:

Output of the example above.

Options.char

You can set it to whatever you want as long as it is a string!

  • options.char[0] - The character to put on the left of the information. ([ is the default)
  • options.char[1] - The character to put on the right of the information. (] is the default)

Example:

require('log-info')({
    char: [ '=>', '<=' ]
});

console.log('A log with a custom character!');

Will result in:

Output of the example above.

Credits

I used some of the code from Bahamas10's log-prefix and modified it a bit to make log-info.