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

bole

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bole - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

10

bole.js

@@ -21,3 +21,3 @@ var stringify = require('json-stringify-safe')

function logger (level, name) {
function levelLogger (level, name) {
return function (inp) {

@@ -82,8 +82,12 @@ var outputs = individual[level]

function bole (name) {
function boleLogger (subname) {
return bole(name + ':' + subname)
}
function makeLogger (p, level) {
p[level] = logger(level, name)
p[level] = levelLogger(level, name)
return p
}
return levels.reduce(makeLogger, {})
return levels.reduce(makeLogger, boleLogger)
}

@@ -90,0 +94,0 @@

{
"name": "bole",
"version": "0.0.1",
"version": "0.1.0",
"description": "A tiny JSON logger",

@@ -5,0 +5,0 @@ "main": "bole.js",

@@ -52,2 +52,3 @@ # bole

* Fast short-circuit where no loggers are configured for the log-level, effectively making log statements a noop where they don't output
* Sub-logger to split a logger for grouping types of events, such as individual HTTP request

@@ -76,2 +77,24 @@ ## API

### logger()
The `logger` object returned by `bole(name)` is also a function that accepts a `name` argument. It returns a new logger whose name is the parent logger with the new name appended after a `':'` character. This is useful for splitting a logger up for grouping events. Consider the HTTP server case where you may want to group all events from a particular request together:
```js
var log = bole('server')
http.createServer(function (req, res) {
req.log = log(uuid.v4()) // make a new sub-logger
req.log.info(req)
//...
// log an error against this sub-logger
req.log.error(err)
})
```
In this case, your events would be listed as something like `"name":"server:93f57a1a-ae59-46da-a625-8d084a77028a"` and each event for a particular request would have the same `"name"` property, distinct from the rest.
Sub-loggers can even be split in to sub-sub loggers, the rabbit hole is ~bottomless.
### bole.output()

@@ -78,0 +101,0 @@

@@ -377,1 +377,44 @@ var http = require('http')

})
test('test sub logger', function (t) {
t.plan(1)
t.on('end', bole.reset)
var sink = bl()
, log = bole('parent')
, expected = []
, sub1
, sub2
bole.output({
level : 'debug'
, stream : sink
})
expected.push(mklogobj('parent', 'debug', { aDebug : 'object' }))
log.debug({ aDebug: 'object' })
expected.push(mklogobj('parent', 'info', { anInfo : 'object' }))
log.info({ anInfo: 'object' })
expected.push(mklogobj('parent', 'warn', { aWarn : 'object' }))
log.warn({ aWarn: 'object' })
expected.push(mklogobj('parent', 'error', { anError : 'object' }))
log.error({ anError: 'object' })
expected.push(mklogobj('parent:sub1', 'debug', { aDebug : 'object' }))
;(sub1 = log('sub1')).debug({ aDebug: 'object' })
expected.push(mklogobj('parent:sub1', 'info', { anInfo : 'object' }))
sub1.info({ anInfo: 'object' })
expected.push(mklogobj('parent:sub2', 'warn', { aWarn : 'object' }))
;(sub2 = log('sub2')).warn({ aWarn: 'object' })
expected.push(mklogobj('parent:sub2:subsub', 'error', { anError : 'object' }))
sub2('subsub').error({ anError: 'object' })
sink.end(function () {
var exp = expected.reduce(function (p, c) {
return p + JSON.stringify(c) + '\n'
}, '')
t.equal(safe(sink.slice().toString()), safe(exp))
})
})
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