| 1 |
liveuser |
1 |
var noop = exports.noop = function(){};
|
|
|
2 |
|
|
|
3 |
exports.extend = function extend(dest, source) {
|
|
|
4 |
for (var prop in source) {
|
|
|
5 |
dest[prop] = source[prop];
|
|
|
6 |
}
|
|
|
7 |
};
|
|
|
8 |
|
|
|
9 |
exports.eventEmitterListenerCount =
|
|
|
10 |
require('events').EventEmitter.listenerCount ||
|
|
|
11 |
function(emitter, type) { return emitter.listeners(type).length; };
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
exports.BufferingLogger = function createBufferingLogger(identifier, uniqueID) {
|
|
|
18 |
var logFunction = require('debug')(identifier);
|
|
|
19 |
if (logFunction.enabled) {
|
|
|
20 |
var logger = new BufferingLogger(identifier, uniqueID, logFunction);
|
|
|
21 |
var debug = logger.log.bind(logger);
|
|
|
22 |
debug.printOutput = logger.printOutput.bind(logger);
|
|
|
23 |
debug.enabled = logFunction.enabled;
|
|
|
24 |
return debug;
|
|
|
25 |
}
|
|
|
26 |
logFunction.printOutput = noop;
|
|
|
27 |
return logFunction;
|
|
|
28 |
};
|
|
|
29 |
|
|
|
30 |
function BufferingLogger(identifier, uniqueID, logFunction) {
|
|
|
31 |
this.logFunction = logFunction;
|
|
|
32 |
this.identifier = identifier;
|
|
|
33 |
this.uniqueID = uniqueID;
|
|
|
34 |
this.buffer = [];
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
BufferingLogger.prototype.log = function() {
|
|
|
38 |
this.buffer.push([ new Date(), Array.prototype.slice.call(arguments) ]);
|
|
|
39 |
return this;
|
|
|
40 |
};
|
|
|
41 |
|
|
|
42 |
BufferingLogger.prototype.clear = function() {
|
|
|
43 |
this.buffer = [];
|
|
|
44 |
return this;
|
|
|
45 |
};
|
|
|
46 |
|
|
|
47 |
BufferingLogger.prototype.printOutput = function(logFunction) {
|
|
|
48 |
if (!logFunction) { logFunction = this.logFunction; }
|
|
|
49 |
var uniqueID = this.uniqueID;
|
|
|
50 |
this.buffer.forEach(function(entry) {
|
|
|
51 |
var date = entry[0].toLocaleString();
|
|
|
52 |
var args = entry[1].slice();
|
|
|
53 |
var formatString = args[0];
|
|
|
54 |
if (formatString !== (void 0) && formatString !== null) {
|
|
|
55 |
formatString = '%s - %s - ' + formatString.toString();
|
|
|
56 |
args.splice(0, 1, formatString, date, uniqueID);
|
|
|
57 |
logFunction.apply(global, args);
|
|
|
58 |
}
|
|
|
59 |
});
|
|
|
60 |
};
|