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

zim-bot

v0.3.6

Published

No dependency better logging for your node app

Downloads

6

Readme

LOG Build Status

No dependency better logging for your node app

Log output

Contents


Install

npm install indent-log

⬆ back to top


Use

Run the logger via:

const Log = require('indent-log');

Log.banner( 'My app started' );
Log.info( 'Server running at #', IPandPort );

Vocabulary

You got a bunch of logs to chose from:

Log.banner('Banner log');
Log.ok('Ok log');
Log.error('Error log');
Log.info('Info log');
Log.done('Done log');
Log.verbose('Verbose log');
Log.hr();
Log.time('Time log');

Log output

Log.hr() will output a line that will fill the terminal and a line break before and after.

Variables

You can add variables by adding them as arguments. Each placeholder # will be replaced one by one with those variables. If you don’t have enough placeholder the variables will be appended at the end:

Log.info( 'running function in folder # to find #', 'folder', 'needle' );

Log.info( 'running function in folder # to find #', 'folder' );

Log.info( 'running function in folder # to find #', 'folder', 'needle', 42, [ 'one', 'two' ] );

Log output

All variables are colored yellow to make reading easier.

Indentation

Logs that run over the space you have in your terminal will automatically indent on the next line:

Log.info('Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ' +
'ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation\nullamco laboris ' +
'nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit ' +
'esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in ' +
'culpa qui officia deserunt mollit anim id est laborum.');

Log output

This can be disabled in the disableIndent setting.

Callbacks

You can register a callback for one or more log types.

Log.callbacks.error = ( text, vars, type ) => DoSomething( text, vars, type );

Now every time you call Log.error the DoSomething function will also be run. This can be useful for error logging, notifications etc.

⬆ back to top


Customize

You can extend the vocabulary of the log yourself by adding a flag and wrapping the Log.Output function:

Log.flags.monkey = ' 🐒  monkey business: ';

Log.monkey = ( text, ...vars ) => console.log( Log.Style.magenta( Log.Output( 'monkey', text, vars ) ) ),

Log.banner('Monkey business starting now!');
Log.monkey('Hey hey!!!');

Log output

Registering a new flag will now ensure all other flags are indented to the largest flag unless it is disabled via the disableIndent setting.

⬆ back to top


Settings

You can change the default settings via:

Log.pretty = true;

An example would be:

const Log = require('indent-log');

if( process.argv.includes('-v') || process.argv.includes('--verbose') ) {
	Log.verboseMode = true;
}

verboseMode

(boolean)
default: false

Toggle verbose output.

verboseFilter

(string)
default: ``

You can filter the verbose output with this regex string. If you want to show only messages with the word foo then you’d use:

Log.verboseFilter = 'foo';

If you want to filter all messages that begin with bar you’d use:

Log.verboseFilter = '^bar';

An example script for your cli app would be:

if( process.argv.includes('-v') || process.argv.includes('--verbose') ) {
	Log.verboseMode = true;

	const flagParam = ( process.argv.indexOf('-v') !== -1 ? process.argv.indexOf('-v') : process.argv.indexOf('--verbose') ) + 1;
	const verboseFilter = process.argv[ flagParam ] && process.argv[ flagParam ].startsWith('-') ? undefined : process.argv[ flagParam ];

	if( verboseFilter ) {
		Log.verboseFilter = verboseFilter;
	}
}

Now the user can use your app with an optional filter like:

yourapp -v onlythisstring

And Log will filter by this word.

disableIndent

(array)
default: [ 'time' ]

All messages are indented by the largest flag of all types. You can disable a particular type if that type has a very large flag that would make indentation of all other look ridicules. Below is what it looks like by default because the type time has it's indent disabled.

Log.banner('Banner log');
Log.ok('Ok log');
Log.error('Error log');
Log.info('Info log');
Log.done('Done log');
Log.verbose('Verbose log');
Log.time('Time log');

Log output

This is what it would look like if you enabled all indentation and included time:

Log.disableIndent = [];

Log.banner('Banner log');
Log.ok('Ok log');
Log.error('Error log');
Log.info('Info log');
Log.done('Done log');
Log.verbose('Verbose log');
Log.time('Time log');

Log output

Enabled:

🔔  INFO: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "var!"
          eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
          veniam, quis nostrud exercitation.

Disabled:

🔔  INFO:
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do "var!" eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
exercitation.

pretty

(boolean)
default: false

Enable pretty printing of variables.

Enabled:

🔥  ERROR: The cause:
           {"thing":"because","more":{"evenmore":[{"reason":"buffer"}]}}

Disabled:

🔥  ERROR: The cause:
           {
            "thing": "because",
            "more": {
             "evenmore": [
              {
               "reason": "buffer"
              }
             ]
            }
           }

flags

(object)

The flags are the strings shown in front of each message. The defaults are:

Log.flags = {
	banner: ` 📣  `,
	error: ` 🔥  ERROR: `,
	info: ` 🔔  INFO: `,
	ok: ` 👍  `,
	done: ` 🚀  DONE: `,
	time: ` 🕐  [${ Log.Style.bold('#timestamp#') }]`,
	verbose: ` 😬  VERBOSE: `,
};

The string #timestamp# is replaced with the current timestamp.

Do note that emojis in node have a very complex way of aligning in the character set. Make sure you either use them consistently or not at all. Calculating the length of a string that contains emojis is difficult and would warrant a dependency like grapheme-splitter. I am trying to keep this package dependency free though.

callbacks

(object)

The callbacks are a collection of functions for each log. The defaults are empty:

Log.callbacks = {
	banner: void( 0 ),
	error: void( 0 ),
	info: void( 0 ),
	ok: void( 0 ),
	done: void( 0 ),
	time: void( 0 ),
	hr: void( 0 ),
	verbose: void( 0 ),
};

If you want the error log eg to do something special every time it’s run, this is where you can do that. Each function has the following parameter passed to it:

@param  {string} text - The message
@param  {array}  vars - All variables passed to the message
@param  {string} type - The type of message

⬆ back to top


Tests

To run the tests for this package run npm test. Jest will run unit tests. There is also a npm run test:watch script that can be used while developing.

⬆ back to top


Release History

See CHANGELOG.

⬆ back to top


License

Copyright (c) Dominik Wilkowski. Licensed under GNU-GPLv3.

⬆ back to top

};