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

booker

v0.2.1

Published

An easy-to-use but powerful node.js command-line logger

Downloads

2

Readme

Loggie

Loggie is a lovely logger for node.js which is SMART, SMALL, and EASY-TO-USE.

Loggie has few options, which makes it work at your will.

Installation

npm install loggie --save

Usage

For most cases, you could use loggie immediately with no extra configurations

var loggie = require('loggie');
logger = loggie();

logger.info('{{cyan install}}', 'loggie'); // will print a cyan 'install', space, and 'loggie'.

You could use typo template here to format your output.

There're several built-in log methods.

Built-in log methods

Method) | Enabled By default) | Binded Argv) | Leading String) ------- | ------------------- | ------------ | ------------------- verbose | no | --verbose | 'VERB ' in gray debug | no | --debug | '[D] ' in magenta error | yes | | bold 'ERR! ' in red warn | yes | | 'WARN ' in yellow info | yes | | (nothing)

logger.debug('blah-blah'); // will do nothing

Because 'debug' is not enabled by default.

But if you start your app with '--debug' option, logger.debug will be activated. Or, you could add 'debug' into log levels in loggie options or with logger.addLevel method.

Programming

loggie(options)

Will create a new loggie instance

options.level

Array.<String>|String

options.level is just the loggie methods you want to activate. For example:

var logger = loggie({
	level: 'info, error' // can also be ['info', 'error']
});

Then, logger.warn('blah-blah') will be deactivated and do nothing.

If set to '*', Loggie will enable all log methods.

options.use_exit

Boolean=

Default to true

If set to true, Loggie will detect 'exit' event of process, if process exited without logger.end() method, it will be considered as a failure.

Best practices

var logger = loggie({
	level: process.env['MY_LOG_LEVEL'] || 
	
		// log level for production
		'info, error, warn'
});

And your environment variables (maybe on Mac OS) could be:

# file: ~/.profile
export MY_LOG_LEVEL=debug,info,error,warn

So, you can use local settings for debugging and development, and will never worry about the possible forgetness of changing debug configurations to production.

Define custom log methods

logger.register({
	detail: {
		template: '{{cyan|bold|underline Detail}} {{arguments}}', // typo template
		argv: '--detail'
	}
});

Then, we defined a log method logger.detail():

logger.detail('a'); // might print a bold cyan 'detail' with a underline, a whitespace, and an 'a'

By default, logger.detail() will do nothing because it is not in the log level list(options.level), but it will be activated if your app is started with '--detail' argument.

You can also use logger.addLevel('detail') to add 'detail' to level list.

.register(methods)

.register(name, setting)

Define your own log method. You can also use this method to override existing log methods.

name

String

The name of the log method you want. If you register() with name = 'verbose', there will be a logger.verbose() method.

setting.template

String

A typo syntax template.

There are several built-in template parameters to be used:

'arguments': arguments joined by a single whitespace (' ')

number: such as '0', the argument at index 0

If you use the template, all arguments will be stringified

Example

logger.register('verbose', {
	template: '{{gray verbose}} {{0}} {{arguments}}'
	// notice that the first argument will be duplicated once
});
logger.verbose('mylabel', 'blah', new Error('error:blah-blah'));

Will print: verbose(gray) mylabel mylabel blah error:blah-blah

setting.fn

function()

The log method.

Notice that if setting.template is defined, setting.fn will be overridden.