debug-logtron
Advanced tools
Comparing version 5.0.0 to 5.1.0
@@ -7,5 +7,4 @@ 'use strict'; | ||
var TypedError = require('error/typed'); | ||
var TermColor = require('term-color'); | ||
var TermColor = require('../lib/term-color.js'); | ||
var validNamespaceRegex = /^[a-zA-Z0-9]+$/; | ||
@@ -35,3 +34,3 @@ var InvalidNamespaceError = TypedError({ | ||
function DebugLogBackend(namespace, opts) { | ||
/*eslint max-statements: [2, 25]*/ | ||
/* eslint max-statements: [2, 25] */ | ||
if (!(this instanceof DebugLogBackend)) { | ||
@@ -95,2 +94,8 @@ return new DebugLogBackend(namespace, opts); | ||
DebugLogBackend.prototype.unwhitelist = function unwhitelist(level, msg) { | ||
var self = this; | ||
self.whitelists[level][msg] = false; | ||
}; | ||
DebugLogBackend.prototype.createStream = function createStream() { | ||
@@ -124,2 +129,3 @@ var self = this; | ||
/* istanbul ignore else */ | ||
if (cb) { | ||
@@ -151,2 +157,3 @@ cb(); | ||
/* istanbul ignore else */ | ||
if (cb) { | ||
@@ -153,0 +160,0 @@ cb(); |
51
index.js
'use strict'; | ||
var LogMessage = require('./log-message.js'); | ||
var util = require('util'); | ||
var BaseLogtron = require('./lib/base-logtron.js'); | ||
var DebugLogBackend = require('./backends/debug-log-backend.js'); | ||
var LEVELS = require('./levels.js').LEVELS_BY_NAME; | ||
@@ -18,47 +19,19 @@ module.exports = DebugLogtron; | ||
this._backend = DebugLogBackend(namespace, opts); | ||
this._stream = this._backend.createStream(); | ||
this._backend = DebugLogBackend(this.name, opts); | ||
BaseLogtron.call(this, { | ||
streams: [this._backend.createStream()] | ||
}); | ||
} | ||
util.inherits(DebugLogtron, BaseLogtron); | ||
DebugLogtron.prototype._log = function _log(level, msg, meta, cb) { | ||
var logMessage = new LogMessage(level, msg, meta); | ||
LogMessage.isValid(logMessage); | ||
this._stream.write(logMessage, cb); | ||
DebugLogtron.prototype.whitelist = function whitelist(level, msg) { | ||
this._backend.whitelist(level, msg); | ||
}; | ||
DebugLogtron.prototype.trace = function trace(msg, meta, cb) { | ||
this._log(LEVELS.trace, msg, meta, cb); | ||
DebugLogtron.prototype.unwhitelist = function unwhitelist(level, msg) { | ||
this._backend.unwhitelist(level, msg); | ||
}; | ||
DebugLogtron.prototype.debug = function debug(msg, meta, cb) { | ||
this._log(LEVELS.debug, msg, meta, cb); | ||
}; | ||
DebugLogtron.prototype.info = function info(msg, meta, cb) { | ||
this._log(LEVELS.info, msg, meta, cb); | ||
}; | ||
DebugLogtron.prototype.access = function access(msg, meta, cb) { | ||
this._log(LEVELS.access, msg, meta, cb); | ||
}; | ||
DebugLogtron.prototype.warn = function warn(msg, meta, cb) { | ||
this._log(LEVELS.warn, msg, meta, cb); | ||
}; | ||
DebugLogtron.prototype.error = function error(msg, meta, cb) { | ||
this._log(LEVELS.error, msg, meta, cb); | ||
}; | ||
DebugLogtron.prototype.fatal = function fatal(msg, meta, cb) { | ||
this._log(LEVELS.fatal, msg, meta, cb); | ||
}; | ||
DebugLogtron.prototype.whitelist = function whitelist(level, msg) { | ||
this._backend.whitelist(level, msg); | ||
}; | ||
DebugLogtron.prototype.items = function items() { | ||
return this._backend.records; | ||
}; |
{ | ||
"name": "debug-logtron", | ||
"version": "5.0.0", | ||
"version": "5.1.0", | ||
"description": "A debug logger with a logtron interface.", | ||
@@ -20,6 +20,7 @@ "keywords": [], | ||
"dependencies": { | ||
"ansi-styles": "^2.0.1", | ||
"collect-parallel": "1.0.1", | ||
"error": "^7.0.1", | ||
"process": "^0.11.1", | ||
"supports-color": "^1.3.1", | ||
"term-color": "1.0.1", | ||
"xtend": "^4.0.0" | ||
@@ -26,0 +27,0 @@ }, |
@@ -43,11 +43,11 @@ # debug-logtron | ||
var test = require('tape'); | ||
test('some module', function t(assert) { | ||
var logger = NullLogtron('mything'); | ||
var thing = new Thing({ logger: logger }) | ||
logger.whitelist('error', 'some msg'); | ||
thing.doStuff(); | ||
var items = logger.items(); | ||
@@ -61,2 +61,6 @@ assert.equal(items.filter(function (x) { | ||
Whilst it is recommended that you minimize state between tests by creating | ||
a new instance of debug-logtron, it is possible to remove a whitelisted item | ||
by calling `.unwhitelist` with the same arguments. | ||
## Interface | ||
@@ -79,3 +83,3 @@ | ||
If you want to add a default logger to your `dependencies` | ||
If you want to add a default logger to your `dependencies` | ||
then I strongly recommend you use [`null-logtron`][null-logtron] | ||
@@ -82,0 +86,0 @@ |
@@ -6,9 +6,8 @@ 'use strict'; | ||
var os = require('os'); | ||
var TermColor = require('term-color'); | ||
var TermColor = require('../lib/term-color.js'); | ||
TermColor.enabled = false; | ||
var DebugLogtron = require('../index.js'); | ||
var LogMessage = require('../log-message.js'); | ||
var LogMessage = require('../lib/log-message.js'); | ||
@@ -407,2 +406,25 @@ test('DebugLogtron is a function', function t(assert) { | ||
test('can unwhitelist errors', function t(assert) { | ||
var logger = allocLogger(); | ||
assert.throws(function throwIt() { | ||
logger.error('oh hi'); | ||
}, /oh hi/); | ||
logger.whitelist('error', 'oh hi'); | ||
logger.error('oh hi'); | ||
assert.equal(logger.items().length, 1); | ||
assert.equal(logger.items()[0].msg, 'oh hi'); | ||
logger.unwhitelist('error', 'oh hi'); | ||
assert.throws(function throwIt() { | ||
logger.error('oh hi'); | ||
}, /oh hi/); | ||
assert.end(); | ||
}); | ||
function allocLogger(opts) { | ||
@@ -409,0 +431,0 @@ opts = opts || {}; |
27616
635
129
6
+ Addedcollect-parallel@1.0.1
+ Addedterm-color@1.0.1
+ Addedansi-styles@2.0.1(transitive)
+ Addedcollect-parallel@1.0.1(transitive)
+ Addedrezult@1.1.0(transitive)
+ Addedterm-color@1.0.1(transitive)
- Removedansi-styles@^2.0.1
- Removedansi-styles@2.2.1(transitive)