Comparing version 1.0.0-b4 to 1.0.0-b5
@@ -0,0 +0,0 @@ /* This Source Code Form is subject to the terms of the Mozilla Public |
@@ -0,0 +0,0 @@ /* This Source Code Form is subject to the terms of the Mozilla Public |
@@ -0,0 +0,0 @@ /* This Source Code Form is subject to the terms of the Mozilla Public |
@@ -0,0 +0,0 @@ /* This Source Code Form is subject to the terms of the Mozilla Public |
@@ -22,5 +22,5 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
ConsoleHandler.prototype.emit = function consoleEmit(record, callback) { | ||
ConsoleHandler.prototype.emit = function consoleEmit(record) { | ||
var handler = (record.level >= LEVELS.WARN) ? this._err : this._out; | ||
handler.emit(record, callback); | ||
handler.emit(record); | ||
}; | ||
@@ -27,0 +27,0 @@ |
@@ -8,4 +8,2 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
const P = require('bluebird'); | ||
const StreamHandler = require('./stream'); | ||
@@ -28,9 +26,2 @@ | ||
FileHandler.prototype._opened = function opened() { | ||
var def = P.pending(); | ||
this._stream = this._open(); | ||
this._stream.once('open', def.fulfill.bind(def)); | ||
return def.promise; | ||
}; | ||
module.exports = FileHandler; |
@@ -5,3 +5,3 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
const P = require('bluebird'); | ||
const deprecate = require('depd')('intel'); | ||
@@ -15,20 +15,10 @@ const Formatter = require('../formatter'); | ||
function promisified() { | ||
return this._emit.apply(this, arguments); | ||
} | ||
function emit(record) { | ||
return this._promisifiedEmit(record); | ||
return this._emit(record, this.__deprecatedCallback); | ||
} | ||
function emitTimeout(record) { | ||
return this._promisifiedEmit(record).timeout(this._timeout); | ||
} | ||
function handleFilter(record) { | ||
if (!this.filter(record)) { | ||
return P.fulfilled(); | ||
if (this.filter(record)) { | ||
this.__emit(record, this.__deprecatedCallback); | ||
} | ||
return this.__emit(record); | ||
} | ||
@@ -42,10 +32,12 @@ | ||
this.setLevel((level !== undefined) ? LEVELS.getLevel(level) : LEVELS.NOTSET); | ||
this.setFormatter(options.formatter); | ||
this.setFormatter(options.formatter || _defaultFormatter); | ||
if ('timeout' in options) { | ||
this._timeout = options.timeout; | ||
} | ||
this._promisifiedEmit = P.promisify(promisified, this); | ||
this.__emit = this._timeout ? emitTimeout : emit; | ||
this.handle = this.__emit; | ||
Filterer.call(this, options); | ||
this.__deprecatedCallback = function deprecated() { | ||
deprecate('Handler.emit callback argument has been removed'); | ||
}; | ||
} | ||
@@ -59,4 +51,2 @@ | ||
_timeout: 1000 * 5, // 5second default timeout? | ||
__toggleFilter: function handlerToggleFilter() { | ||
@@ -68,10 +58,10 @@ Filterer.prototype.__toggleFilter.call(this); | ||
// sub-classes should override emit, not handle | ||
_emit: function emit(/*record, callback*/) { | ||
_emit: function emit(/*record*/) { | ||
throw new Error('Handler.emit must be implemented by sub-classes'); | ||
}, | ||
__emit: emit, | ||
format: function format(record) { | ||
var formatter = this._formatter || _defaultFormatter; | ||
return formatter.format(record); | ||
return this._formatter.format(record); | ||
}, | ||
@@ -99,4 +89,4 @@ | ||
} | ||
if (val.length !== 2) { | ||
throw new Error('emit must accept 2 arguments (record, callback)'); | ||
if (val.length === 2) { | ||
deprecate('Handler.emit callback argument has been removed'); | ||
} | ||
@@ -108,3 +98,9 @@ | ||
Object.defineProperty(Handler.prototype, '_timeout', { | ||
set: function() { | ||
deprecate('Handler.timeout option has been removed'); | ||
} | ||
}); | ||
module.exports = Handler; |
@@ -14,7 +14,4 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
NullHandler.prototype._timeout = 0; | ||
NullHandler.prototype.emit = function nullEmit(record, callback){ | ||
callback(); | ||
}; | ||
NullHandler.prototype.emit = function nullEmit(){}; | ||
module.exports = NullHandler; |
@@ -20,6 +20,6 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
StreamHandler.prototype.emit = function streamEmit(record, callback) { | ||
this._stream.write(this.format(record) + '\n', callback); | ||
StreamHandler.prototype.emit = function streamEmit(record) { | ||
this._stream.write(this.format(record) + '\n'); | ||
}; | ||
module.exports = StreamHandler; |
@@ -0,0 +0,0 @@ /* This Source Code Form is subject to the terms of the Mozilla Public |
@@ -8,3 +8,2 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
const dbug = require('dbug')('intel:logger'); | ||
const P = require('bluebird'); | ||
@@ -51,5 +50,3 @@ const klass = require('./utils/klass'); | ||
function logNoop() { | ||
return P.fulfilled(); | ||
} | ||
function logNoop() {} | ||
@@ -197,12 +194,16 @@ function disableLevels(logger) { | ||
err[Record._UNCAUGHT_SYMBOL] = true; | ||
var promise = this.critical(err); | ||
var logger = this; | ||
this.critical(err); | ||
if (exits) { | ||
//XXX: wrap in timeout | ||
promise.then(function() { | ||
logger._process.exit(1); | ||
}); | ||
this._exit(); | ||
} | ||
}, | ||
_exit: function _exit() { | ||
var logger = this; | ||
var t = setTimeout(function() { | ||
logger._process.exit(1); | ||
}, 5000); | ||
t.unref(); | ||
}, | ||
makeRecord: function makeRecord(name, level, msg, args) { | ||
@@ -213,4 +214,2 @@ return new Record(name, level, msg, args); | ||
handle: function handle(record) { | ||
var promises = []; | ||
if (this.filter(record)) { | ||
@@ -221,3 +220,3 @@ | ||
if (record.level >= this._handlers[i].level) { | ||
promises.push(this._handlers[i].handle(record)); | ||
this._handlers[i].handle(record); | ||
} | ||
@@ -230,3 +229,3 @@ } | ||
if (par) { | ||
promises.push(par.handle(record)); | ||
par.handle(record); | ||
} | ||
@@ -238,10 +237,2 @@ } | ||
} | ||
if (promises.length > 1) { | ||
return P.all(promises); | ||
} else if (promises[0]) { | ||
return promises[0]; | ||
} else { | ||
return P.fulfilled(); | ||
} | ||
}, | ||
@@ -272,5 +263,3 @@ | ||
if (this.isEnabledFor(level)) { | ||
return this._log.apply(this, arguments); | ||
} else { | ||
return P.fulfilled(); | ||
this._log.apply(this, arguments); | ||
} | ||
@@ -277,0 +266,0 @@ }, |
@@ -16,2 +16,3 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
const HOSTNAME = require('os').hostname(); | ||
const MESSAGE_CACHE = '__message:' + Math.random(); | ||
@@ -32,13 +33,2 @@ // stack formatter helper | ||
function lazy(proto, name, fn) { | ||
Object.defineProperty(proto, name, { | ||
configure: true, | ||
enumerable: true, | ||
get: function lazyGetter() { | ||
var val = fn.call(this); | ||
return this[name] = val; | ||
} | ||
}); | ||
} | ||
function Trace(fn) { | ||
@@ -60,2 +50,3 @@ Error.captureStackTrace(this, fn); | ||
this.v = LOG_VERSION; | ||
this.timestamp = Date.now(); | ||
@@ -75,24 +66,40 @@ var i = args.length; | ||
this.stack = trace ? stack(trace) : undefined; | ||
} | ||
lazy(Record.prototype, 'timestamp', function() { | ||
return new Date(); | ||
}); | ||
Record.prototype.name = undefined; | ||
Record.prototype.level = undefined; | ||
Record.prototype.levelname = undefined; | ||
Record.prototype.args = undefined; | ||
Record.prototype.pid = undefined; | ||
Record.prototype.host = undefined; | ||
Record.prototype.v = undefined; | ||
Record.prototype.timestamp = undefined; | ||
Record.prototype.exception = undefined; | ||
Record.prototype.uncaughtException = undefined; | ||
Record.prototype.stack = undefined; | ||
Record.prototype[MESSAGE_CACHE] = undefined; | ||
lazy(Record.prototype, 'message', function() { | ||
var args = this.args; | ||
var message = args[0]; | ||
var isString = typeof message === 'string'; | ||
if (!isString || args.length > 1) { | ||
if (!isString) { | ||
args = new Array(this.args.length + 1); | ||
args[0] = '%?'; | ||
var i = args.length - 1; | ||
while (i--) { | ||
args[i + 1] = this.args[i]; | ||
Object.defineProperty(Record.prototype, 'message', { | ||
enumerable: true, | ||
get: function() { | ||
if (!this[MESSAGE_CACHE]) { | ||
var args = this.args; | ||
var message = args[0]; | ||
var isString = typeof message === 'string'; | ||
if (!isString || args.length > 1) { | ||
if (!isString) { | ||
args = new Array(this.args.length + 1); | ||
args[0] = '%?'; | ||
var i = args.length - 1; | ||
while (i--) { | ||
args[i + 1] = this.args[i]; | ||
} | ||
} | ||
message = printf.apply(null, args); | ||
} | ||
this[MESSAGE_CACHE] = message; | ||
} | ||
message = printf.apply(null, args); | ||
return this[MESSAGE_CACHE]; | ||
} | ||
return message; | ||
}); | ||
@@ -106,4 +113,6 @@ | ||
var key = keys[i]; | ||
if (key === 'args') { | ||
json.message = this[key]; | ||
if (key === 'message' || key === MESSAGE_CACHE) { | ||
// nothing | ||
} else if (key === 'timestamp') { | ||
json[key] = new Date(this[key]); | ||
} else { | ||
@@ -110,0 +119,0 @@ json[key] = this[key]; |
@@ -0,0 +0,0 @@ /* This Source Code Form is subject to the terms of the Mozilla Public |
@@ -0,0 +0,0 @@ /* This Source Code Form is subject to the terms of the Mozilla Public |
@@ -0,0 +0,0 @@ /* This Source Code Form is subject to the terms of the Mozilla Public |
@@ -0,0 +0,0 @@ /* This Source Code Form is subject to the terms of the Mozilla Public |
{ | ||
"name": "intel", | ||
"version": "1.0.0-b4", | ||
"version": "1.0.0-b5", | ||
"dependencies": { | ||
"bluebird": "^2.2.1", | ||
"chalk": "~0.5.1", | ||
"dbug": "~0.4.1", | ||
"depd": "~1.0.0", | ||
"stack-trace": "~0.0.9", | ||
@@ -15,3 +15,4 @@ "strftime": "~0.8.0", | ||
"blanket": "~1.1.6", | ||
"debug": "~1.0.2", | ||
"bluebird": "~2.3.2", | ||
"debug": "~2.0.0", | ||
"insist": "0.x", | ||
@@ -29,4 +30,3 @@ "jshint": "2.x", | ||
"scripts": { | ||
"test": "mocha --check-leaks --ui exports", | ||
"coverage": "mocha --ui exports --require blanket -R ../../../test/util/reporter", | ||
"test": "mocha --check-leaks --ui exports --require blanket -R ../../../test/util/reporter", | ||
"bench": "matcha -I exports" | ||
@@ -37,3 +37,6 @@ }, | ||
"pattern": "lib", | ||
"data-cover-never": ["node_modules", "test"] | ||
"data-cover-never": [ | ||
"node_modules", | ||
"test" | ||
] | ||
} | ||
@@ -48,3 +51,4 @@ }, | ||
"engines": { | ||
"node": ">=0.10.0" | ||
"node": ">=0.8.0", | ||
"npm": ">=1.4.7" | ||
}, | ||
@@ -60,6 +64,8 @@ "keywords": [ | ||
"author": "Sean McArthur <sean.monstar@gmail.com> (http://seanmonstar.com)", | ||
"licenses" : [{ | ||
"type": "MPL 2.0", | ||
"url": "https://mozilla.org/MPL/2.0/" | ||
}], | ||
"licenses": [ | ||
{ | ||
"type": "MPL 2.0", | ||
"url": "https://mozilla.org/MPL/2.0/" | ||
} | ||
], | ||
"files": [ | ||
@@ -66,0 +72,0 @@ "LICENSE", |
@@ -26,3 +26,2 @@ # intel | ||
- [Logging Exceptions](#logging-exceptions) | ||
- [Async Logging](#async-logging) | ||
- [Handlers](#handlers) | ||
@@ -144,10 +143,2 @@ - [ConsoleHandler](#consolehandler) | ||
### Async logging | ||
With Nodejs' async nature, many handlers will be dealing with asynchronous APIs. In most cases, that shouldn't be your concern, and you can ignore this. However, if you need to execute code after a log message has been completely handled, every log method returns a promise. The promise only gets resolved after all handlers have finished handling that message. | ||
```js | ||
require('intel').warn('report in').then(rogerThat); | ||
``` | ||
## Handlers | ||
@@ -157,3 +148,3 @@ | ||
All Handlers have a `level`, `timeout`, and a [`Formatter`](#formatters). The `timeout` will cause the promise returned by `log` to be rejected if the handler doesn't complete within the time frame. | ||
All Handlers have a `level` and a [`Formatter`](#formatters). | ||
@@ -160,0 +151,0 @@ ```js |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10
75966
10
22
1341
462
+ Addeddepd@~1.0.0
+ Addeddepd@1.0.1(transitive)
- Removedbluebird@^2.2.1
- Removedbluebird@2.11.0(transitive)