some jsstyle'ing

This commit is contained in:
Trent Mick 2012-04-27 17:23:29 -07:00
parent a442418f2d
commit 11b91cadd4

View file

@ -4,13 +4,13 @@
* The bunyan logging library for node.js.
*/
var VERSION = "0.7.1";
var VERSION = '0.7.1';
// Bunyan log format version. This becomes the 'v' field on all log records.
// `0` is until I release a version "1.0.0" of node-bunyan. Thereafter,
// `0` is until I release a version '1.0.0' of node-bunyan. Thereafter,
// starting with `1`, this will be incremented if there is any backward
// incompatible change to the log record format. Details will be in
// "CHANGES.md" (the change log).
// 'CHANGES.md' (the change log).
var LOG_VERSION = 0;
@ -62,8 +62,9 @@ if (!format) {
var i = 1;
var args = arguments;
var len = args.length;
var str = String(f).replace(formatRegExp, function(x) {
if (i >= len) return x;
var str = String(f).replace(formatRegExp, function (x) {
if (i >= len)
return x;
switch (x) {
case '%s': return String(args[i++]);
case '%d': return Number(args[i++]);
@ -95,7 +96,7 @@ function getCaller3Info() {
var savePrepare = Error.prepareStackTrace;
Error.stackTraceLimit = 3;
Error.captureStackTrace(this, getCaller3Info);
Error.prepareStackTrace = function(_, stack) {
Error.prepareStackTrace = function (_, stack) {
var caller = stack[2];
obj.file = caller.getFileName();
obj.line = caller.getLineNumber();
@ -155,7 +156,7 @@ var levelFromName = {
};
function resolveLevel(nameOrNum) {
var level = (typeof(nameOrNum) === 'string'
var level = (typeof (nameOrNum) === 'string'
? levelFromName[nameOrNum]
: nameOrNum);
if (! (TRACE <= level && level <= FATAL)) {
@ -172,13 +173,13 @@ function resolveLevel(nameOrNum) {
* Create a Logger instance.
*
* @param options {Object} See documentation for full details. At minimum
* this must include a "name" string key. Configuration keys:
* this must include a 'name' string key. Configuration keys:
* - streams: specify the logger output streams. This is an array of
* objects of the form:
* {
* "level": "info", // optional, "info" default
* "stream": process.stdout, // "stream" or "path" is required
* "closeOnExit": false // optional, default depends
* 'level': 'info', // optional, "info" default
* 'stream': process.stdout, // 'stream' or "path" is required
* 'closeOnExit': false // optional, default depends
* }
* See README.md for full details.
* - `level`: set the level for a single output stream (cannot be used
@ -232,7 +233,7 @@ function Logger(options, _childOptions, _childSimple) {
if (options.streams && !Array.isArray(options.streams)) {
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))) {
throw new TypeError('invalid options.serializers: must be an object')
}
@ -290,9 +291,9 @@ function Logger(options, _childOptions, _childSimple) {
var type = s.type;
if (!s.type) {
if (s.stream) {
s.type = "stream";
s.type = 'stream';
} else if (s.path) {
s.type = "file"
s.type = 'file'
}
}
@ -306,12 +307,12 @@ function Logger(options, _childOptions, _childSimple) {
}
switch (s.type) {
case "stream":
case 'stream':
if (!s.closeOnExit) {
s.closeOnExit = false;
}
break;
case "file":
case 'file':
if (!s.stream) {
s.stream = fs.createWriteStream(s.path,
{flags: 'a', encoding: 'utf8'});
@ -337,7 +338,7 @@ function Logger(options, _childOptions, _childSimple) {
}
Object.keys(serializers).forEach(function (field) {
var serializer = serializers[field];
if (typeof(serializer) !== "function") {
if (typeof (serializer) !== 'function') {
throw new TypeError(format(
'invalid serializer for "%s" field: must be a function', field));
} else {
@ -349,7 +350,7 @@ function Logger(options, _childOptions, _childSimple) {
// Handle *config* options.
if (options.stream) {
addStream({
type: "stream",
type: 'stream',
stream: options.stream,
closeOnExit: false,
level: (options.level ? resolveLevel(options.level) : INFO)
@ -358,7 +359,7 @@ function Logger(options, _childOptions, _childSimple) {
options.streams.forEach(addStream);
} else if (!parent) {
addStream({
type: "stream",
type: 'stream',
stream: process.stdout,
closeOnExit: false,
level: (options.level ? resolveLevel(options.level) : INFO)
@ -370,7 +371,7 @@ function Logger(options, _childOptions, _childSimple) {
if (options.src) {
this.src = true;
}
xxx("Logger: ", self)
xxx('Logger: ', self)
// Fields.
// These are the default fields for log records (minus the attributes
@ -402,13 +403,13 @@ function Logger(options, _childOptions, _childSimple) {
* Create a child logger, typically to add a few log record fields.
*
* This can be useful when passing a logger to a sub-component, e.g. a
* "wuzzle" component of your service:
* 'wuzzle' component of your service:
*
* var wuzzleLog = log.child({component: "wuzzle"})
* var wuzzleLog = log.child({component: 'wuzzle'})
* var wuzzle = new Wuzzle({..., log: wuzzleLog})
*
* Then log records from the wuzzle code will have the same structure as
* the app log, *plus the component="wuzzle" field*.
* the app log, *plus the component='wuzzle' field*.
*
* @param options {Object} Optional. Set of options to apply to the child.
* All of the same options for a new Logger apply here. Notes:
@ -419,7 +420,7 @@ function Logger(options, _childOptions, _childSimple) {
* @param simple {Boolean} Optional. Set to true to assert that `options`
* (a) only add fields (no config) and (b) no serialization handling is
* required for them. IOW, this is a fast path for frequent child
* creation. See "tools/timechild.js" for numbers.
* creation. See 'tools/timechild.js' for numbers.
*/
Logger.prototype.child = function (options, simple) {
return new Logger(this, options || {}, simple);
@ -429,7 +430,7 @@ Logger.prototype.child = function (options, simple) {
///**
// * Close this logger.
// *
// * This closes streams (that it owns, as per "endOnClose" attributes on
// * 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 () {
@ -439,7 +440,7 @@ Logger.prototype.child = function (options, simple) {
// if (!this._isSimpleChild) {
// self.streams.forEach(function (s) {
// if (s.endOnClose) {
// xxx("closing stream s:", s);
// xxx('closing stream s:', s);
// s.stream.end();
// s.endOnClose = false;
// }
@ -458,7 +459,7 @@ Logger.prototype.child = function (options, simple) {
*
* Set Usage:
* log.level(INFO) // set all streams to level INFO
* log.level("info") // can use "info" et al aliases
* log.level('info') // can use 'info' et al aliases
*/
Logger.prototype.level = function level(value) {
if (value === undefined) {
@ -482,12 +483,12 @@ Logger.prototype.level = function level(value) {
*
* // Returns a level of the identified stream.
* log.levels(0) -> TRACE // level of stream at index 0
* log.levels("foo") // level of stream with name "foo"
* log.levels('foo') // level of stream with name 'foo'
*
* Set Usage:
* log.levels(0, INFO) // set level of stream 0 to INFO
* log.levels(0, "info") // can use "info" et al aliases
* log.levels("foo", WARN) // set stream named "foo" to WARN
* log.levels(0, 'info') // can use 'info' et al aliases
* log.levels('foo', WARN) // set stream named 'foo' to WARN
*
* Stream names: When streams are defined, they can optionally be given
* a name. For example,
@ -501,7 +502,7 @@ Logger.prototype.level = function level(value) {
* ...
*
* @param name {String|Number} The stream index or name.
* @param value {Number|String} The level value (INFO) or alias ("info").
* @param value {Number|String} The level value (INFO) or alias ('info').
* If not given, this is a 'get' operation.
* @throws {Error} If there is no stream with the given name.
*/
@ -615,7 +616,7 @@ Logger.prototype._emit = function (rec) {
obj[k] = recFields[k];
});
}
xxx("Record:", rec)
xxx('Record:', rec)
obj.msg = format.apply(this, rec[3]);
if (!obj.time) {
obj.time = (new Date());
@ -632,8 +633,8 @@ Logger.prototype._emit = function (rec) {
str = JSON.stringify(obj) + '\n';
} catch (e) {
var src = ((obj.src && obj.src.file) ? obj.src : getCaller3Info());
var emsg = format("bunyan: ERROR: could not stringify log record from "
+ "%s:%d: %s", src.file, src.line, e);
var emsg = format('bunyan: ERROR: could not stringify log record from '
+ '%s:%d: %s', src.file, src.line, e);
var eobj = objCopy(rec[0]);
eobj.bunyanMsg = emsg;
eobj.msg = obj.msg;
@ -647,7 +648,7 @@ Logger.prototype._emit = function (rec) {
}
}
this.streams.forEach(function(s) {
this.streams.forEach(function (s) {
if (s.level <= level) {
xxx('writing log rec "%s" to "%s" stream (%d <= %d)', obj.msg, s.type,
s.level, level);