| 1 |
"use strict"; |
| 2 |
|
| 3 |
var aFrom = require("es5-ext/array/from") |
| 4 |
, partial = require("es5-ext/function/#/partial") |
| 5 |
, mixin = require("es5-ext/object/mixin") |
| 6 |
, ee = require("event-emitter"); |
| 7 |
|
| 8 |
var logger; |
| 9 |
|
| 10 |
logger = ee( |
| 11 |
(exports = { |
| 12 |
init: function () { |
| 13 |
this.msg = []; |
| 14 |
this.closure = 0; |
| 15 |
this.passed = []; |
| 16 |
this.errored = []; |
| 17 |
this.failed = []; |
| 18 |
this.started = new Date(); |
| 19 |
return this; |
| 20 |
}, |
| 21 |
in: function (msg, closure) { |
| 22 |
this.msg.push(msg); |
| 23 |
if (closure) ++this.closure; |
| 24 |
}, |
| 25 |
out: function (closure) { |
| 26 |
this.msg.pop(); |
| 27 |
if (closure) --this.closure; |
| 28 |
}, |
| 29 |
log: function (type, data) { |
| 30 |
var result = { type: type, time: new Date(), data: data, msg: aFrom(this.msg) }; |
| 31 |
this.push(result); |
| 32 |
this[type + "ed"].push(result); |
| 33 |
this.emit("data", result); |
| 34 |
}, |
| 35 |
end: function () { this.emit("end"); } |
| 36 |
}) |
| 37 |
); |
| 38 |
|
| 39 |
logger.log.partial = partial; |
| 40 |
logger.error = logger.log.partial("error"); |
| 41 |
logger.pass = logger.log.partial("pass"); |
| 42 |
logger.fail = logger.log.partial("fail"); |
| 43 |
|
| 44 |
module.exports = function () { return mixin([], logger).init(); }; |