Socket
Socket
Sign inDemoInstall

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 - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

docs/command-line-help.txt

22

package.json
{
"name": "filter-log",
"version": "0.0.1",
"version": "0.0.2",
"description": "flexible, minimalistic logging",
"main": "filter-log.js",
"scripts": {
"test": "node_modules/mocha/bin/mocha"
"test": "node_modules/mocha/bin/mocha",
"testDebug": "node_modules/mocha/bin/mocha --inspect --debug-brk"
},

@@ -13,2 +14,5 @@ "repository": {

},
"bin": {
"filter-log": "./filter-log-command.js"
},
"keywords": [

@@ -24,3 +28,15 @@ "logging",

},
"homepage": "https://github.com/EmergentIdeas/filter-log#readme"
"homepage": "https://github.com/EmergentIdeas/filter-log#readme",
"devDependencies": {
"chai": "^4.0.2",
"mocha": "^3.4.2"
},
"dependencies": {
"JSONStream": "^1.3.1",
"is-stream": "^1.1.0",
"minimist": "^1.2.0",
"through2": "^2.0.3",
"tripartite": "^1.0.7",
"underscore": "^1.8.3"
}
}
# filter-log
flexible, minimalistic logging
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.
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