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

filter-log

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filter-log

flexible, minimalistic logging

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
decreased by-85.37%
Maintainers
1
Weekly downloads
 
Created
Source

filter-log

flexible, minimalistic event-bus style logging

Description

Logging is really two things.

  1. Creating information about what code is doing.
  2. Doing something with that information (like saving it or filtering it).

Filter log separates those concerns using the event bus pattern. Code that produces log entries get tools that make event log entries easy to create and informational. The application can set up how log events will be captured and saved. Log events are JS objects so we can save lots of information.

The Basic Boring Example

var filog = require('filter-log')
filog.defineProcessor(process.stdout)
var log = filog()
log.info('hello, world!')

Here we've done the basics. Line 2 creates a processor which is listening for log entries. It has no filter and will log absolutely everything. Since no transformer was specfied, the log entries will be formatted as streamable JSON.

Line 3 creates a new logger. It has the basic tools you'd expect for logging by level and string interpolation. Line 4 creates a new log entry, sets the level to "info" and publishes it.

If you run this example, a JSON formatted log entry will show up in stdout.

Logging more Data

Strings are fine, but objects contain more information. Let's log an object.

log.write({ event: 'vip login', firstName: 'John'})

The object above will be augmented with date information and (given the processor set up in the first example) logged to std out. Filter log loggers are streams. You can write and pipe data to them like normal streams.

Letting the Logger Help

Lots of times the logger will have contextual information you want to save with every log entry. This could be just the name of the component creating the log entry or could be selected configuration items that are determing behavior or environmental information that will help with debugging. Let's create a logger which with will help us keep our code DRY.

var log = filog('my-auth-component', { hostName: require('os').hostname() })
log.info('successful log in for %s', userName)

A couple new things. When we created the logger on line 1, we gave it a name, my-auth-component. This will be used to identify all log entries created through this logger. We also set a single property that will be added to every log entry, the hostName. On line 2, we've used string interpolation to make it a little easier to create a message.

Keywords

FAQs

Package last updated on 05 Jul 2017

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