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

consologger

v1.1.0

Published

A simple logger so you can manage all your 'console.log()' from a main lib. Feel free to make requests, report bugs, and suggest ideas.

Downloads

23

Readme

consologger

[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [downloads-image]: http://img.shields.io/npm/dm/consologger.svg [npm-url]: https://npmjs.org/package/consologger [npm-image]: https://img.shields.io/npm/v/consologger.svg

A simple logger so you can manage all your 'console.log()' from a main lib. Styled output, dynamic prefixing and custom presets. Feel free to make requests, report bugs, and suggest ideas.

prototypes were not harmed in making this library

Example for the browser version

Let's see a simple example. ( we assume you use browserify or something so you can use the module on the browser )

//	Get the module, which is a constructor.
var Consologger = require('consologger');

//	Make a new instance for logging.
var logger = new Consologger();

//	Let's start logging.
//	We make some green text.
logger.green('Here\'s some green text');

//	And then we print it.
logger.print();

You should have some green text in the console! Big deal.

Chaining

You can chain those calls.

So the above would become

logger
.green('Here\'s some green text')
.print();

Now, you can also chain presets ( styles basically ). For example, u is the preset for underline and mono is the preset for monospace font.

logger
.u.mono.red('red monospace for retro errors')
.print();

And you can add more text/presets before hitting print, so that will result in a line with those combined.

logger
.red('[ERROR] ')
.mono.bgRed('Ln 0 Col 0')
//	text is the "plain" preset, without any styles
.text(' Some error happened there (go fix it!)')
.print();

Presets

There are some presets coming with the module, covering the most common and simple use cases. you can see them in the presets.json file.

But it's very easy to add your own presets. Here's an example

var Consologger = require('consologger');
var logger = new Consologger();
var myNewStyle;

myNewStyle = {
	name: 'cyanItalic',
	//	style is basically CSS
	style: {
		color: 'cyan',
		'font-style': 'italic'
	}
};

logger
.addPreset(myNewStyle);

logger
.cyanItalic('my fancy cyan text')
.print();

logger
.text('✅')
.green.lThrough('make a module to make logging awesome')
.print();

Prefix

You can add a prefix on a consologger instance. Let's say I'm in a context in my code where I want to separate visually whether the logging I see comes from that context or not.

var foo = function(){

	var fooLogger = new Consologger();

	fooLogger
	.bgRed.mono('[ foo() ]')
	.prefix();

	// ...
	fooLogger
	.red('not this error again')
	.print();
};

setTimeout(foo, 500);

var logger = new Consologger();

logger
.red('not this error again')
.print();

node.js version

For node there are some presets with terminal specific stuff.

.addPreset doesn't work because it makes no sense to add a new preset...

API

Consologger

contructor of a new consologger instance. That new instance can hold prefix state.

.preset

when using a preset ( see list of presets here ), you add the style of that preset to the current styles of the consologger instance.

.preset(text)

when passing a text to a preset function, you apply the current styles to that text, and keep it in the consologger line buffer. ( for now, only strings are accepted )

.print()

prints whatever the line buffer has, with the styles applied on each string separately. If the consologger instance has a prefix set, that's going to be prepended to the line buffer.

.prefix()

takes the line buffer and saves is as a prefix so that every next .print() will inlude the prefix value first.

.addPreset(presetObject)

Adds a new preset. presetObject must have a 'name' field with a string value, and a 'style' field that's an object and has the CSS values you want to apply. ( for now, you cannot override presets that already exist )

.switchOff()

Will make the print function do nothing. Effectively turning off printing.

.switchOn()

Will make the print function print again, reverting any previous switchOff call.