more jsstyle'ing

This commit is contained in:
Trent Mick 2012-04-27 17:31:46 -07:00
parent 11b91cadd4
commit 1a916f6ad7

View file

@ -51,7 +51,7 @@ if (!format) {
var inspect = util.inspect; var inspect = util.inspect;
var formatRegExp = /%[sdj%]/g; var formatRegExp = /%[sdj%]/g;
format = function format(f) { format = function format(f) {
if (typeof f !== 'string') { if (typeof (f) !== 'string') {
var objects = []; var objects = [];
for (var i = 0; i < arguments.length; i++) { for (var i = 0; i < arguments.length; i++) {
objects.push(inspect(arguments[i])); objects.push(inspect(arguments[i]));
@ -75,7 +75,7 @@ if (!format) {
} }
}); });
for (var x = args[i]; i < len; x = args[++i]) { for (var x = args[i]; i < len; x = args[++i]) {
if (x === null || typeof x !== 'object') { if (x === null || typeof (x) !== 'object') {
str += ' ' + x; str += ' ' + x;
} else { } else {
str += ' ' + inspect(x); str += ' ' + inspect(x);
@ -228,13 +228,14 @@ function Logger(options, _childOptions, _childSimple) {
} }
} }
if ((options.stream || options.level) && options.streams) { if ((options.stream || options.level) && options.streams) {
throw new TypeError('cannot mix "streams" with "stream" or "level" options'); throw new TypeError(
'cannot mix "streams" with "stream" or "level" options');
} }
if (options.streams && !Array.isArray(options.streams)) { if (options.streams && !Array.isArray(options.streams)) {
throw new TypeError('invalid options.streams: must be an array') throw new TypeError('invalid options.streams: must be an array')
} }
if (options.serializers && (typeof (options.serializers) !== 'object' if (options.serializers && (typeof (options.serializers) !== 'object' ||
|| Array.isArray(options.serializers))) { Array.isArray(options.serializers))) {
throw new TypeError('invalid options.serializers: must be an object') throw new TypeError('invalid options.serializers: must be an object')
} }
@ -427,27 +428,29 @@ Logger.prototype.child = function (options, simple) {
} }
///** /* BEGIN JSSTYLED */
// * Close this logger. /**
// * * Close this logger.
// * This closes streams (that it owns, as per 'endOnClose' attributes on *
// * streams), etc. Typically you **don't** need to bother calling this. * This closes streams (that it owns, as per 'endOnClose' attributes on
// */ * streams), etc. Typically you **don't** need to bother calling this.
//Logger.prototype.close = function () { Logger.prototype.close = function () {
// if (this._closed) { if (this._closed) {
// return; return;
// } }
// if (!this._isSimpleChild) { if (!this._isSimpleChild) {
// self.streams.forEach(function (s) { self.streams.forEach(function (s) {
// if (s.endOnClose) { if (s.endOnClose) {
// xxx('closing stream s:', s); xxx('closing stream s:', s);
// s.stream.end(); s.stream.end();
// s.endOnClose = false; s.endOnClose = false;
// } }
// }); });
// } }
// this._closed = true; this._closed = true;
//} }
*/
/* END JSSTYLED */
/** /**
@ -495,7 +498,7 @@ Logger.prototype.level = function level(value) {
* log = new Logger({ * log = new Logger({
* streams: [ * streams: [
* { * {
* name: 'foo', // <--- proposed new option, yucky controlling uniqueness * name: 'foo',
* path: '/var/log/my-service/foo.log' * path: '/var/log/my-service/foo.log'
* level: 'trace' * level: 'trace'
* }, * },
@ -509,10 +512,11 @@ Logger.prototype.level = function level(value) {
Logger.prototype.levels = function levels(name, value) { Logger.prototype.levels = function levels(name, value) {
if (name === undefined) { if (name === undefined) {
assert.equal(value, undefined); assert.equal(value, undefined);
return this.streams.map(function (s) { return s.level }); return this.streams.map(
function (s) { return s.level });
} }
var stream; var stream;
if (typeof name === 'number') { if (typeof (name) === 'number') {
stream = this.streams[name]; stream = this.streams[name];
if (stream === undefined) { if (stream === undefined) {
throw new Error('invalid stream index: ' + name); throw new Error('invalid stream index: ' + name);
@ -557,7 +561,7 @@ Logger.prototype._applySerializers = function (fields, keys) {
var applyKeys = fields; var applyKeys = fields;
if (keys) { if (keys) {
applyKeys = {}; applyKeys = {};
for (var i=0; i < keys.length; i++) { for (var i = 0; i < keys.length; i++) {
applyKeys[keys[i]] = true; applyKeys[keys[i]] = true;
} }
} }
@ -686,7 +690,7 @@ Logger.prototype.trace = function () {
} else { } else {
msgArgs = Array.prototype.slice.call(arguments, 1); msgArgs = Array.prototype.slice.call(arguments, 1);
} }
} else if (typeof arguments[0] === 'string') { // `log.trace(msg, ...)` } else if (typeof (arguments[0]) === 'string') { // `log.trace(msg, ...)`
fields = null; fields = null;
msgArgs = Array.prototype.slice.call(arguments); msgArgs = Array.prototype.slice.call(arguments);
} else { // `log.trace(fields, msg, ...)` } else { // `log.trace(fields, msg, ...)`
@ -725,7 +729,7 @@ Logger.prototype.debug = function () {
} else { } else {
msgArgs = Array.prototype.slice.call(arguments, 1); msgArgs = Array.prototype.slice.call(arguments, 1);
} }
} else if (typeof arguments[0] === 'string') { // `log.debug(msg, ...)` } else if (typeof (arguments[0]) === 'string') { // `log.debug(msg, ...)`
fields = null; fields = null;
msgArgs = Array.prototype.slice.call(arguments); msgArgs = Array.prototype.slice.call(arguments);
} else { // `log.debug(fields, msg, ...)` } else { // `log.debug(fields, msg, ...)`
@ -764,7 +768,7 @@ Logger.prototype.info = function () {
} else { } else {
msgArgs = Array.prototype.slice.call(arguments, 1); msgArgs = Array.prototype.slice.call(arguments, 1);
} }
} else if (typeof arguments[0] === 'string') { // `log.info(msg, ...)` } else if (typeof (arguments[0]) === 'string') { // `log.info(msg, ...)`
fields = null; fields = null;
msgArgs = Array.prototype.slice.call(arguments); msgArgs = Array.prototype.slice.call(arguments);
} else { // `log.info(fields, msg, ...)` } else { // `log.info(fields, msg, ...)`
@ -803,7 +807,7 @@ Logger.prototype.warn = function () {
} else { } else {
msgArgs = Array.prototype.slice.call(arguments, 1); msgArgs = Array.prototype.slice.call(arguments, 1);
} }
} else if (typeof arguments[0] === 'string') { // `log.warn(msg, ...)` } else if (typeof (arguments[0]) === 'string') { // `log.warn(msg, ...)`
fields = null; fields = null;
msgArgs = Array.prototype.slice.call(arguments); msgArgs = Array.prototype.slice.call(arguments);
} else { // `log.warn(fields, msg, ...)` } else { // `log.warn(fields, msg, ...)`
@ -842,7 +846,7 @@ Logger.prototype.error = function () {
} else { } else {
msgArgs = Array.prototype.slice.call(arguments, 1); msgArgs = Array.prototype.slice.call(arguments, 1);
} }
} else if (typeof arguments[0] === 'string') { // `log.error(msg, ...)` } else if (typeof (arguments[0]) === 'string') { // `log.error(msg, ...)`
fields = null; fields = null;
msgArgs = Array.prototype.slice.call(arguments); msgArgs = Array.prototype.slice.call(arguments);
} else { // `log.error(fields, msg, ...)` } else { // `log.error(fields, msg, ...)`
@ -881,7 +885,7 @@ Logger.prototype.fatal = function () {
} else { } else {
msgArgs = Array.prototype.slice.call(arguments, 1); msgArgs = Array.prototype.slice.call(arguments, 1);
} }
} else if (typeof arguments[0] === 'string') { // `log.fatal(msg, ...)` } else if (typeof (arguments[0]) === 'string') { // `log.fatal(msg, ...)`
fields = null; fields = null;
msgArgs = Array.prototype.slice.call(arguments); msgArgs = Array.prototype.slice.call(arguments);
} else { // `log.fatal(fields, msg, ...)` } else { // `log.fatal(fields, msg, ...)`