Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

event2log

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event2log

Translates events to human-readable log

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

event2log

Little helper module for translating events into log messages.

Will perfectly work with NodeJS 4.0.0 and above.

Example

'use strict';

const events = require( 'events' );
const event2log = require( 'event2log' );


// First we create a dummy instance. It might be anything emitting events.
// This is the instance you are willing to observe and log upon emitted events.
let instanceThrowingEvents = new events.EventEmitter();

// The translation table converts events into human-readable strings.
// The field name corresponds to an event name. The field itself accommodates a
// function that receives the event arguments and alway will return an array!
// The first argument of that array names a logging method and the following
// items will be passed to logging method as arguments.
const translationTable = {
	'event1': ( a, b ) => [ 'log',   `Hello ${a}! Are you afraid of ${b}?` ],
	'event2': ( c )    => [ 'error', `${c} is watching you!` ]
};

// The following statement bundles everything together. For testing purposes it
// just prints stuff to the console. But you also could replace the 'console' by
// something more sophisticated (or bloated?) like 'winston'.
let e2lHandler = event2log( translationTable, instanceThrowingEvents, console );


instanceThrowingEvents.emit( 'event1', "World", "Chuck Norris" );
// Will print to stdout: Hello World! Are you afraid of Chuck Norris?

instanceThrowingEvents.emit( 'event2', "Big Brother" );
// Will print to stderr: Big Brother is watching you!


// Calling the returned e2lHandler releases all listening events bound by
// event2log.
e2lHandler();

instanceThrowingEvents.emit( 'event1', "Universe", "human beings" );
// Won't print anything to the console.

Keywords

FAQs

Package last updated on 18 Apr 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc