diff --git a/bin/bunyan b/bin/bunyan index b0ba281..5ad950b 100755 --- a/bin/bunyan +++ b/bin/bunyan @@ -20,8 +20,8 @@ var child_process = require('child_process'), var assert = require('assert'); var nodeSpawnSupportsStdio = ( - Number(process.version.split('.')[0]) >= 0 - || Number(process.version.split('.')[1]) >= 8); + Number(process.version.split('.')[0]) >= 0 || + Number(process.version.split('.')[1]) >= 8); @@ -103,6 +103,7 @@ function getVersion() { var format = util.format; if (!format) { + /* BEGIN JSSTYLED */ // If not node 0.6, then use its `util.format`: // : var inspect = util.inspect; @@ -140,6 +141,7 @@ if (!format) { } return str; }; + /* END JSSTYLED */ } function indent(s) { @@ -399,7 +401,7 @@ function parseArgv(argv) { var endOfOptions = false; while (args.length > 0) { var arg = args.shift(); - switch(arg) { + switch (arg) { case '--': endOfOptions = true; break; @@ -438,7 +440,7 @@ function parseArgv(argv) { } parsed.outputMode = OM_FROM_NAME[name]; if (parsed.outputMode === undefined) { - throw new Error('unknown output mode: \''+name+"'"); + throw new Error('unknown output mode: "'+name+'"'); } break; case '-j': // output with JSON.stringify @@ -979,7 +981,7 @@ function processStdin(opts, stylize, callback) { } leftover = lines.pop(); length -= 1; - for (var i=1; i < length; i++) { + for (var i = 1; i < length; i++) { handleLogLine(null, lines[i], opts, stylize); } }); @@ -1095,7 +1097,7 @@ function processPids(opts, stylize, callback) { } leftover = lines.pop(); length -= 1; - for (var i=1; i < length; i++) { + for (var i = 1; i < length; i++) { handleLogLine(null, lines[i], opts, stylize); } }); @@ -1165,7 +1167,7 @@ function processFile(file, opts, stylize, callback) { } leftover = lines.pop(); length -= 1; - for (var i=1; i < length; i++) { + for (var i = 1; i < length; i++) { handleLogLine(file, lines[i], opts, stylize); } }); @@ -1186,6 +1188,7 @@ function processFile(file, opts, stylize, callback) { /** * From node async module. */ +/* BEGIN JSSTYLED */ function asyncForEach(arr, iterator, callback) { callback = callback || function () {}; if (!arr.length) { @@ -1207,6 +1210,7 @@ function asyncForEach(arr, iterator, callback) { }); }); }; +/* END JSSTYLED */ @@ -1316,7 +1320,7 @@ function main(argv) { return; } if (opts.pid && opts.args.length > 0) { - warn("bunyan: error: can't use both '-p PID' (%s) and file (%s) args", + warn('bunyan: error: can\'t use both "-p PID" (%s) and file (%s) args', opts.pid, opts.args.join(' ')); return drainStdoutAndExit(1); } @@ -1334,18 +1338,19 @@ function main(argv) { // Pager. var nodeVer = process.versions.node.split('.').map(Number); var paginate = ( - process.stdout.isTTY - && process.stdin.isTTY - && !opts.pids // Don't page if following process output. - && opts.args.length > 0 // Don't page if no file args to process. - && process.platform !== 'win32' - && nodeVer >= [0,8,0] - && (opts.paginate === true - || (opts.paginate !== false - && (!process.env.BUNYAN_NO_PAGER - || process.env.BUNYAN_NO_PAGER.length === 0)))); + process.stdout.isTTY && + process.stdin.isTTY && + !opts.pids && // Don't page if following process output. + opts.args.length > 0 && // Don't page if no file args to process. + process.platform !== 'win32' && + nodeVer >= [0, 8, 0] && + (opts.paginate === true || + (opts.paginate !== false && + (!process.env.BUNYAN_NO_PAGER || + process.env.BUNYAN_NO_PAGER.length === 0)))); if (paginate) { var pagerCmd = process.env.PAGER || 'less'; + /* JSSTYLED */ assert.ok(pagerCmd.indexOf('"') === -1 && pagerCmd.indexOf("'") === -1, 'cannot parse PAGER quotes yet'); var argv = pagerCmd.split(/\s+/g); @@ -1363,7 +1368,7 @@ function main(argv) { pager = spawn(argv[0], argv.slice(1), // Share the stderr handle to have error output come // straight through. Only supported in v0.8+. - {env: env, stdio: ['pipe',1,2]}); + {env: env, stdio: ['pipe', 1, 2]}); stdout = pager.stdin; // Early termination of the pager: just stop. @@ -1431,7 +1436,7 @@ if (require.main === module) { // place. The real fix is that `.end()` shouldn't be called on stdout // in node core. Node v0.6.9 fixes that. Only guard for v0.6.0..v0.6.8. var nodeVer = process.versions.node.split('.').map(Number); - if ([0,6,0] <= nodeVer && nodeVer <= [0,6,8]) { + if ([0, 6, 0] <= nodeVer && nodeVer <= [0, 6, 8]) { var stdout = process.stdout; stdout.end = stdout.destroy = stdout.destroySoon = function () { /* pass */ diff --git a/examples/long-running.js b/examples/long-running.js index 7583aaf..5d5e8cb 100644 --- a/examples/long-running.js +++ b/examples/long-running.js @@ -50,7 +50,7 @@ function logOne() { var msg = [randchoice(words), randchoice(words)].join(' '); var delay = randint(300); //console.warn('long-running about to log.%s(..., "%s")', level, msg) - log[level]({"word": randchoice(words), "delay": delay}, msg); + log[level]({'word': randchoice(words), 'delay': delay}, msg); timeout = setTimeout(logOne, delay); } diff --git a/examples/ringbuffer.js b/examples/ringbuffer.js index 74ffb31..4ca76fd 100644 --- a/examples/ringbuffer.js +++ b/examples/ringbuffer.js @@ -3,11 +3,11 @@ var bunyan = require('..'); var ringbuffer = new bunyan.RingBuffer({ limit: 100 }); var log = new bunyan({ name: 'foo', - streams: [{ + streams: [ { type: 'raw', stream: ringbuffer, level: 'debug' - }] + } ] }); log.info('hello world'); diff --git a/lib/bunyan.js b/lib/bunyan.js index 2d28640..1ab6334 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -638,8 +638,9 @@ Logger.prototype._applySerializers = function (fields, excludeFields) { // Check each serializer against these (presuming number of serializers // is typically less than number of fields). Object.keys(this.serializers).forEach(function (name) { - if (fields[name] === undefined - || (excludeFields && excludeFields[name])) { + if (fields[name] === undefined || + (excludeFields && excludeFields[name])) + { return; } xxx('_applySerializers; apply to "%s" key', name) @@ -900,7 +901,7 @@ var errSerializer = Logger.stdSerializers.err = function err(err) { function safeCycles() { var seen = []; return function (key, val) { - if (!val || typeof val !== 'object') { + if (!val || typeof (val) !== 'object') { return val; } if (seen.indexOf(val) !== -1) { diff --git a/test/buffer.test.js b/test/buffer.test.js index 5f3f419..5bc656a 100644 --- a/test/buffer.test.js +++ b/test/buffer.test.js @@ -48,10 +48,10 @@ test('log.info(BUFFER)', function (t) { var rec = catcher.records[catcher.records.length - 1]; t.equal(rec.msg, inspect(b), format('log.%s msg is inspect(BUFFER)', lvl)); - t.ok(rec["0"] === undefined, - 'no "0" array index key in record: ' + inspect(rec["0"])); - t.ok(rec["parent"] === undefined, - 'no "parent" array index key in record: ' + inspect(rec["parent"])); + t.ok(rec['0'] === undefined, + 'no "0" array index key in record: ' + inspect(rec['0'])); + t.ok(rec['parent'] === undefined, + 'no "parent" array index key in record: ' + inspect(rec['parent'])); log[lvl].call(log, b, 'bar'); var rec = catcher.records[catcher.records.length - 1]; diff --git a/test/child-behaviour.test.js b/test/child-behaviour.test.js index 0689b26..1109b3e 100644 --- a/test/child-behaviour.test.js +++ b/test/child-behaviour.test.js @@ -29,21 +29,21 @@ test('child can add stream', function (t) { var dadStream = new CapturingStream(); var dad = bunyan.createLogger({ name: 'surname', - streams: [{ + streams: [ { type: 'raw', stream: dadStream, level: 'info' - }] + } ] }); var sonStream = new CapturingStream(); var son = dad.child({ component: 'son', - streams: [{ + streams: [ { type: 'raw', stream: sonStream, level: 'debug' - }] + } ] }); dad.info('info from dad'); @@ -66,11 +66,11 @@ test('child can set level of inherited streams', function (t) { var dadStream = new CapturingStream(); var dad = bunyan.createLogger({ name: 'surname', - streams: [{ + streams: [ { type: 'raw', stream: dadStream, level: 'info' - }] + } ] }); // Intention here is that the inherited `dadStream` logs at 'debug' level @@ -99,11 +99,11 @@ test('child can set level of inherited streams and add streams', function (t) { var dadStream = new CapturingStream(); var dad = bunyan.createLogger({ name: 'surname', - streams: [{ + streams: [ { type: 'raw', stream: dadStream, level: 'info' - }] + } ] }); // Intention here is that the inherited `dadStream` logs at 'debug' level @@ -112,11 +112,11 @@ test('child can set level of inherited streams and add streams', function (t) { var son = dad.child({ component: 'son', level: 'trace', - streams: [{ + streams: [ { type: 'raw', stream: sonStream, level: 'debug' - }] + } ] }); dad.info('info from dad'); diff --git a/test/cycles.test.js b/test/cycles.test.js index 83f569f..1ec4bdb 100644 --- a/test/cycles.test.js +++ b/test/cycles.test.js @@ -31,27 +31,27 @@ outstr.end = function (c) { var expect = [ { - "name": "blammo", - "level": 30, - "msg": "bango { bang: 'boom', KABOOM: [Circular] }", - "v": 0 + 'name': 'blammo', + 'level': 30, + 'msg': 'bango { bang: \'boom\', KABOOM: [Circular] }', + 'v': 0 }, { - "name": "blammo", - "level": 30, - "msg": "kaboom { bang: 'boom', KABOOM: [Circular] }", - "v": 0 + 'name': 'blammo', + 'level': 30, + 'msg': 'kaboom { bang: \'boom\', KABOOM: [Circular] }', + 'v': 0 }, { - "name": "blammo", - "level": 30, - "bang": "boom", - "KABOOM": { - "bang": "boom", - "KABOOM": "[Circular]" + 'name': 'blammo', + 'level': 30, + 'bang': 'boom', + 'KABOOM': { + 'bang': 'boom', + 'KABOOM': '[Circular]' }, - "msg": "", - "v": 0 + 'msg': '', + 'v': 0 } ]; diff --git a/test/dtrace.test.js b/test/dtrace.test.js index 062b740..0f90ac2 100644 --- a/test/dtrace.test.js +++ b/test/dtrace.test.js @@ -47,15 +47,15 @@ test('basic dtrace', function (t) { 'bunyan$target:::log-*{printf("%s", copyinstr(arg0))}', '-c', format('node %s/log-some.js', __dirname)]; var dtrace = spawn(argv[0], argv.slice(1)); - //console.error("ARGV: %j", argv); + //console.error('ARGV: %j', argv); var traces = []; dtrace.stdout.on('data', function (data) { - //console.error("DTRACE STDOUT:", data.toString()); + //console.error('DTRACE STDOUT:', data.toString()); traces.push(data.toString()); }); dtrace.stderr.on('data', function (data) { - console.error("DTRACE STDERR:", data.toString()); + console.error('DTRACE STDERR:', data.toString()); }); dtrace.on('exit', function (code) { t.notOk(code, 'dtrace exited cleanly'); diff --git a/test/error-event.test.js b/test/error-event.test.js index 9c138f9..4adf845 100644 --- a/test/error-event.test.js +++ b/test/error-event.test.js @@ -19,7 +19,7 @@ var test = tap4nodeunit.test; test('error event on log write', function (t) { LOG_PATH = '/this/path/is/bogus.log' var log = bunyan.createLogger( - {name: 'error-event', streams: [{path: LOG_PATH}]}); + {name: 'error-event', streams: [ {path: LOG_PATH} ]}); log.on('error', function (err, stream) { t.ok(err, 'got err in error event: ' + err); t.equal(err.code, 'ENOENT', 'error code is ENOENT'); diff --git a/test/log-some.js b/test/log-some.js index 997fd64..2e3a893 100644 --- a/test/log-some.js +++ b/test/log-some.js @@ -10,4 +10,3 @@ var log = bunyan.createLogger({ }); log.debug({foo: 'bar'}, 'hi at debug') log.trace('hi at trace') - diff --git a/test/serializers.test.js b/test/serializers.test.js index d4b5a78..c58a7d3 100644 --- a/test/serializers.test.js +++ b/test/serializers.test.js @@ -48,11 +48,11 @@ test('req serializer', function (t) { {}, 1, 'string', - [1,2,3], + [1, 2, 3], {'foo':'bar'} ]; for (var i = 0; i < bogusReqs.length; i++) { - log.info({req: bogusReqs[i]}, "hi"); + log.info({req: bogusReqs[i]}, 'hi'); t.equal(records[i].req, bogusReqs[i]); } @@ -65,7 +65,7 @@ test('req serializer', function (t) { res.end('Hello World\n'); }) server.listen(8765, function () { - http.get({host: '127.0.0.1', port: 8765, path: '/'}, function(res) { + http.get({host: '127.0.0.1', port: 8765, path: '/'}, function (res) { res.resume(); log.info({req: theReq}, 'the request'); var lastRecord = records[records.length-1]; @@ -106,11 +106,11 @@ test('res serializer', function (t) { {}, 1, 'string', - [1,2,3], + [1, 2, 3], {'foo':'bar'} ]; for (var i = 0; i < bogusRess.length; i++) { - log.info({res: bogusRess[i]}, "hi"); + log.info({res: bogusRess[i]}, 'hi'); t.equal(records[i].res, bogusRess[i]); } @@ -123,7 +123,7 @@ test('res serializer', function (t) { res.end('Hello World\n'); }) server.listen(8765, function () { - http.get({host: '127.0.0.1', port: 8765, path: '/'}, function(res) { + http.get({host: '127.0.0.1', port: 8765, path: '/'}, function (res) { res.resume(); log.info({res: theRes}, 'the response'); var lastRecord = records[records.length-1]; @@ -162,11 +162,11 @@ test('err serializer', function (t) { {}, 1, 'string', - [1,2,3], + [1, 2, 3], {'foo':'bar'} ]; for (var i = 0; i < bogusErrs.length; i++) { - log.info({err: bogusErrs[i]}, "hi"); + log.info({err: bogusErrs[i]}, 'hi'); t.equal(records[i].err, bogusErrs[i]); } @@ -185,10 +185,10 @@ test('err serializer: long stack', function (t) { var records = []; var log = bunyan.createLogger({ name: 'serializer-test', - streams: [{ + streams: [ { stream: new CapturingStream(records), type: 'raw' - }], + } ], serializers: { err: bunyan.stdSerializers.err } @@ -269,10 +269,10 @@ test('do not apply serializers if no record key', function (t) { var records = []; var log = bunyan.createLogger({ name: 'serializer-test', - streams: [{ + streams: [ { stream: new CapturingStream(records), type: 'raw' - }], + } ], serializers: { err: bunyan.stdSerializers.err, boom: function (value) {