added some compatability stuff for 0.8. Dropping support for 0.6 which seems really old anyway

This commit is contained in:
Spencer Alger
2013-11-05 12:19:41 -07:00
parent bb814c2bab
commit ca29fbe6e3
9 changed files with 105 additions and 34 deletions

View File

@ -3,7 +3,6 @@ node_js:
- "0.11"
- "0.10"
- "0.8"
- "0.6"
services:
- elasticsearch
before_script:

View File

@ -14781,6 +14781,8 @@ if (process.browser) {
};
}
/**
* Log bridge, which is an [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter)
* that sends events to one or more outputs/loggers. Setup these loggers by
@ -14833,12 +14835,21 @@ _.inherits(Log, EventEmitter);
Log.prototype.close = function () {
this.emit('closing');
if (EventEmitter.listenerCount(this)) {
if (this.listenerCount()) {
console.error('Something is still listening for log events, but the logger is closing.');
this.clearAllListeners();
}
};
Log.prototype.listenerCount = function (event) {
// compatability for node < 0.10
if (EventEmitter.listenerCount) {
return EventEmitter.listenerCount(this, event);
} else {
return this.listeners(event).length;
}
};
/**
* Levels observed by the loggers, ordered by rank
*
@ -14972,7 +14983,7 @@ Log.prototype.addOutput = function (config) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.error = function (e) {
if (EventEmitter.listenerCount(this, 'error')) {
if (this.listenerCount('error')) {
return this.emit('error', e instanceof Error ? e : new Error(e));
}
};
@ -14986,7 +14997,7 @@ Log.prototype.error = function (e) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.warning = function (/* ...msg */) {
if (EventEmitter.listenerCount(this, 'warning')) {
if (this.listenerCount('warning')) {
return this.emit('warning', Log.join(arguments));
}
};
@ -15000,7 +15011,7 @@ Log.prototype.warning = function (/* ...msg */) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.info = function (/* ...msg */) {
if (EventEmitter.listenerCount(this, 'info')) {
if (this.listenerCount('info')) {
return this.emit('info', Log.join(arguments));
}
};
@ -15013,7 +15024,7 @@ Log.prototype.info = function (/* ...msg */) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.debug = function (/* ...msg */) {
if (EventEmitter.listenerCount(this, 'debug')) {
if (this.listenerCount('debug')) {
return this.emit('debug', Log.join(arguments) /*+ _.getStackTrace(Log.prototype.debug)*/);
}
};
@ -15031,7 +15042,7 @@ Log.prototype.debug = function (/* ...msg */) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.trace = function (method, requestUrl, body, responseBody, responseStatus) {
if (EventEmitter.listenerCount(this, 'trace')) {
if (this.listenerCount('trace')) {
if (typeof requestUrl === 'string') {
requestUrl = url.parse(requestUrl, true, true);
}

File diff suppressed because one or more lines are too long

23
dist/elasticsearch.js vendored
View File

@ -14785,6 +14785,8 @@ if (process.browser) {
};
}
/**
* Log bridge, which is an [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter)
* that sends events to one or more outputs/loggers. Setup these loggers by
@ -14837,12 +14839,21 @@ _.inherits(Log, EventEmitter);
Log.prototype.close = function () {
this.emit('closing');
if (EventEmitter.listenerCount(this)) {
if (this.listenerCount()) {
console.error('Something is still listening for log events, but the logger is closing.');
this.clearAllListeners();
}
};
Log.prototype.listenerCount = function (event) {
// compatability for node < 0.10
if (EventEmitter.listenerCount) {
return EventEmitter.listenerCount(this, event);
} else {
return this.listeners(event).length;
}
};
/**
* Levels observed by the loggers, ordered by rank
*
@ -14976,7 +14987,7 @@ Log.prototype.addOutput = function (config) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.error = function (e) {
if (EventEmitter.listenerCount(this, 'error')) {
if (this.listenerCount('error')) {
return this.emit('error', e instanceof Error ? e : new Error(e));
}
};
@ -14990,7 +15001,7 @@ Log.prototype.error = function (e) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.warning = function (/* ...msg */) {
if (EventEmitter.listenerCount(this, 'warning')) {
if (this.listenerCount('warning')) {
return this.emit('warning', Log.join(arguments));
}
};
@ -15004,7 +15015,7 @@ Log.prototype.warning = function (/* ...msg */) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.info = function (/* ...msg */) {
if (EventEmitter.listenerCount(this, 'info')) {
if (this.listenerCount('info')) {
return this.emit('info', Log.join(arguments));
}
};
@ -15017,7 +15028,7 @@ Log.prototype.info = function (/* ...msg */) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.debug = function (/* ...msg */) {
if (EventEmitter.listenerCount(this, 'debug')) {
if (this.listenerCount('debug')) {
return this.emit('debug', Log.join(arguments) /*+ _.getStackTrace(Log.prototype.debug)*/);
}
};
@ -15035,7 +15046,7 @@ Log.prototype.debug = function (/* ...msg */) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.trace = function (method, requestUrl, body, responseBody, responseStatus) {
if (EventEmitter.listenerCount(this, 'trace')) {
if (this.listenerCount('trace')) {
if (typeof requestUrl === 'string') {
requestUrl = url.parse(requestUrl, true, true);
}

File diff suppressed because one or more lines are too long

View File

@ -114,9 +114,7 @@ fs.readdirSync(path.resolve(__dirname)).forEach(function (filename) {
var name = filename.replace(/\..+$/, '');
if (name !== 'index') {
templates[name] = _.template(
fs.readFileSync(path.resolve(__dirname, filename), {
encoding: 'utf8'
}),
fs.readFileSync(path.resolve(__dirname, filename), 'utf8'),
null,
{
imports: templateGlobals

View File

@ -13,6 +13,8 @@ if (process.browser) {
};
}
/**
* Log bridge, which is an [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter)
* that sends events to one or more outputs/loggers. Setup these loggers by
@ -65,12 +67,21 @@ _.inherits(Log, EventEmitter);
Log.prototype.close = function () {
this.emit('closing');
if (EventEmitter.listenerCount(this)) {
if (this.listenerCount()) {
console.error('Something is still listening for log events, but the logger is closing.');
this.clearAllListeners();
}
};
Log.prototype.listenerCount = function (event) {
// compatability for node < 0.10
if (EventEmitter.listenerCount) {
return EventEmitter.listenerCount(this, event);
} else {
return this.listeners(event).length;
}
};
/**
* Levels observed by the loggers, ordered by rank
*
@ -204,7 +215,7 @@ Log.prototype.addOutput = function (config) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.error = function (e) {
if (EventEmitter.listenerCount(this, 'error')) {
if (this.listenerCount('error')) {
return this.emit('error', e instanceof Error ? e : new Error(e));
}
};
@ -218,7 +229,7 @@ Log.prototype.error = function (e) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.warning = function (/* ...msg */) {
if (EventEmitter.listenerCount(this, 'warning')) {
if (this.listenerCount('warning')) {
return this.emit('warning', Log.join(arguments));
}
};
@ -232,7 +243,7 @@ Log.prototype.warning = function (/* ...msg */) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.info = function (/* ...msg */) {
if (EventEmitter.listenerCount(this, 'info')) {
if (this.listenerCount('info')) {
return this.emit('info', Log.join(arguments));
}
};
@ -245,7 +256,7 @@ Log.prototype.info = function (/* ...msg */) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.debug = function (/* ...msg */) {
if (EventEmitter.listenerCount(this, 'debug')) {
if (this.listenerCount('debug')) {
return this.emit('debug', Log.join(arguments) /*+ _.getStackTrace(Log.prototype.debug)*/);
}
};
@ -263,7 +274,7 @@ Log.prototype.debug = function (/* ...msg */) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.trace = function (method, requestUrl, body, responseBody, responseStatus) {
if (EventEmitter.listenerCount(this, 'trace')) {
if (this.listenerCount('trace')) {
if (typeof requestUrl === 'string') {
requestUrl = url.parse(requestUrl, true, true);
}

View File

@ -17,22 +17,37 @@ var LoggerAbstract = require('../logger'),
_ = require('../utils'),
fs = require('fs');
// var = lessThanZeroTen (function () {
// var numbs = _.map(process.versions.node.split('.'), function (num) {
// return _.parseInt(num);
// });
// return numbs[0] === 0 && numbs[1] < 10;
// }());
function Stream(config, bridge) {
// if (lessThanZeroTen) {
// throw new Error('The stream logger is only compatible with node 0.10 and greater');
// }
Stream.callSuper(this, arguments);
_.makeBoundMethods(this);
if (config.stream instanceof nodeStreams.Writable) {
if (config.stream.write && config.stream.end) {
this.stream = config.stream;
} else {
throw new TypeError('Invalid stream, use an instance of stream.Writeable');
}
process.on('exit', this.bound.onProcessExit);
if (this.stream._writableState && this.stream._writableState.buffer) {
process.on('exit', this.bound.onProcessExit);
}
// else you should probably flush your stream
}
_.inherits(Stream, LoggerAbstract);
// flush the write buffer to stderr synchronously
Stream.prototype.onProcessExit = _.handler(function () {
// process is dying, lets manually flush the buffer synchronously to stderr.
var writeBuffer = this.stream._writableState.buffer;
if (writeBuffer && writeBuffer.length) {
console.error('Log stream did not get to finish writing. Flushing to stderr');

View File

@ -33299,6 +33299,8 @@ if (process.browser) {
};
}
/**
* Log bridge, which is an [EventEmitter](http://nodejs.org/api/events.html#events_class_events_eventemitter)
* that sends events to one or more outputs/loggers. Setup these loggers by
@ -33351,12 +33353,21 @@ _.inherits(Log, EventEmitter);
Log.prototype.close = function () {
this.emit('closing');
if (EventEmitter.listenerCount(this)) {
if (this.listenerCount()) {
console.error('Something is still listening for log events, but the logger is closing.');
this.clearAllListeners();
}
};
Log.prototype.listenerCount = function (event) {
// compatability for node < 0.10
if (EventEmitter.listenerCount) {
return EventEmitter.listenerCount(this, event);
} else {
return this.listeners(event).length;
}
};
/**
* Levels observed by the loggers, ordered by rank
*
@ -33490,7 +33501,7 @@ Log.prototype.addOutput = function (config) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.error = function (e) {
if (EventEmitter.listenerCount(this, 'error')) {
if (this.listenerCount('error')) {
return this.emit('error', e instanceof Error ? e : new Error(e));
}
};
@ -33504,7 +33515,7 @@ Log.prototype.error = function (e) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.warning = function (/* ...msg */) {
if (EventEmitter.listenerCount(this, 'warning')) {
if (this.listenerCount('warning')) {
return this.emit('warning', Log.join(arguments));
}
};
@ -33518,7 +33529,7 @@ Log.prototype.warning = function (/* ...msg */) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.info = function (/* ...msg */) {
if (EventEmitter.listenerCount(this, 'info')) {
if (this.listenerCount('info')) {
return this.emit('info', Log.join(arguments));
}
};
@ -33531,7 +33542,7 @@ Log.prototype.info = function (/* ...msg */) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.debug = function (/* ...msg */) {
if (EventEmitter.listenerCount(this, 'debug')) {
if (this.listenerCount('debug')) {
return this.emit('debug', Log.join(arguments) /*+ _.getStackTrace(Log.prototype.debug)*/);
}
};
@ -33549,7 +33560,7 @@ Log.prototype.debug = function (/* ...msg */) {
* @return {Boolean} - True if any outputs accepted the message
*/
Log.prototype.trace = function (method, requestUrl, body, responseBody, responseStatus) {
if (EventEmitter.listenerCount(this, 'trace')) {
if (this.listenerCount('trace')) {
if (typeof requestUrl === 'string') {
requestUrl = url.parse(requestUrl, true, true);
}
@ -34013,22 +34024,37 @@ var LoggerAbstract = require('../logger'),
_ = require('../utils'),
fs = require('fs');
// var = lessThanZeroTen (function () {
// var numbs = _.map(process.versions.node.split('.'), function (num) {
// return _.parseInt(num);
// });
// return numbs[0] === 0 && numbs[1] < 10;
// }());
function Stream(config, bridge) {
// if (lessThanZeroTen) {
// throw new Error('The stream logger is only compatible with node 0.10 and greater');
// }
Stream.callSuper(this, arguments);
_.makeBoundMethods(this);
if (config.stream instanceof nodeStreams.Writable) {
if (config.stream.write && config.stream.end) {
this.stream = config.stream;
} else {
throw new TypeError('Invalid stream, use an instance of stream.Writeable');
}
process.on('exit', this.bound.onProcessExit);
if (this.stream._writableState && this.stream._writableState.buffer) {
process.on('exit', this.bound.onProcessExit);
}
// else you should probably flush your stream
}
_.inherits(Stream, LoggerAbstract);
// flush the write buffer to stderr synchronously
Stream.prototype.onProcessExit = _.handler(function () {
// process is dying, lets manually flush the buffer synchronously to stderr.
var writeBuffer = this.stream._writableState.buffer;
if (writeBuffer && writeBuffer.length) {
console.error('Log stream did not get to finish writing. Flushing to stderr');