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

custom-log

v0.3.1

Published

A tiny flexible logger

Downloads

8

Readme

custom-log

A tiny (~2kb) flexible logger, very basic, simple and fast. Will add some features over time.

custom-log is targeted at the Browser as a tiny helper that makes available any custom log function you can create yourself, and which can be enabled/disabled individually.

Although there are plenty full-fledged loggers for use in node, you can use this one instead if you don't need a zillion features but rather prefer simplicity.


How to use?

First install:

Browser: <script src="./custom-log.min.js"></script>

Node: npm install --save custom-log

<function> customLog( <string>/<object> init )

Returns a log function based on the init argument. The init argument can be either a string or an object. If init is a string, only the base log function's prefix can be set with a string. In case init is an object, multiple custom log functions with their own prefix strings can be defined in the init object. To set the base log function prefix in a init object, use the reserved 'log' key. See some examples below:


// customLog is global when loaded in browser, for node use:
const customLog= require( 'custom-log' );


// create a single log function without prefix:
const log= customLog();

log( 'hey!' );
// hey!


// create a log function with multiple custom log functions attached to it
// you can silently enable/disable by adding settings if needed:
const settings = {
	silentDisable	: false	// default
	silentEnable	: false	// default
};

const log= customLog({
	info		: 'INFO: ',
	warning		: 'WARNING: ',
	error		: 'ERROR: ',
	listener	: 'LISTENER: ',
	dal			: 'DAL: '
	// use the result of a function as prefix for logs
	time		: () => new Date()
}, settings );

log( 'hello' );
// hello

log.info( 'easy!' );
// INFO: easy!

log.dal( 'Success! Payload: ', 'some payload' );
// DAL: Success! Payload: some payload

// now temporarily turn off dal messages:
log.dal.disable();

// and turn them on again:
log.dal.enable();

// disable or enable multiple levels at once
// arguments can be either (space seperated)String, Array of strings, multiple Strings
log.disable( 'dal listener error log' );
// or
log.enable( 'error', 'listener', 'log' );
// or
log.enable( ['error', 'listener', 'log'] );

change log

0.3.0

  • removes log.assert
  • adds dynamic function prefix
  • adds 'silentEnable' and 'silentDisable' initialization modes

0.2.3

  • removes leading space for default log without prefix
  • log.assert is way too naive and you better use something like the 'assert' npm lib for that. log.assert is now deprecated and will be removed over time.

0.2.1

changes license to MIT


0.1.9

Fixed bug that caused a crash on using the disable or enable function


0.1.6

Added log.assert function


0.1.0

Initial commit.


###license

MIT