Socket
Socket
Sign inDemoInstall

custom-log

Package Overview
Dependencies
0
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    custom-log

A tiny flexible logger


Version published
Weekly downloads
16
decreased by-5.88%
Maintainers
1
Install size
18.6 kB
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 29 Jul 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc