From bb8664a5597f4d4024d82647e75417ba2028ddbc Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Mon, 4 Jun 2012 23:19:39 -0700 Subject: [PATCH] jsstyling of example files --- Makefile | 2 +- examples/err.js | 68 +++++++++++++++++++------------------ examples/handle-fs-error.js | 1 - examples/hi.js | 22 ++++++------ examples/level.js | 9 +++-- examples/multi.js | 16 ++++----- examples/server.js | 56 +++++++++++++++--------------- examples/src.js | 17 +++++----- examples/unstringifyable.js | 7 ++-- 9 files changed, 99 insertions(+), 99 deletions(-) diff --git a/Makefile b/Makefile index d1f8c1d..b474205 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ TAP := ./node_modules/.bin/tap #---- Files -JSSTYLE_FILES := $(shell find lib test tools -name "*.js") +JSSTYLE_FILES := $(shell find lib test tools examples -name "*.js") diff --git a/examples/err.js b/examples/err.js index 0efe01b..2eacc7f 100644 --- a/examples/err.js +++ b/examples/err.js @@ -5,52 +5,54 @@ var Logger = require('../lib/bunyan'); var util = require('util'); var log = new Logger({ - name: "myserver", + name: 'myserver', serializers: { err: Logger.stdSerializers.err, // <--- use this } }); try { - throw new TypeError("boom"); + throw new TypeError('boom'); } catch (err) { - log.warn({err: err}, "operation went boom: %s", err) // <--- here + log.warn({err: err}, 'operation went boom: %s', err) // <--- here } -log.info(new TypeError("how about this?")) // <--- alternatively this +log.info(new TypeError('how about this?')) // <--- alternatively this try { - throw "boom string"; + throw 'boom string'; } catch (err) { log.error(err) } -/* - -$ node err.js | ../bin/bunyan -j -{ - "name": "myserver", - "hostname": "banana.local", - "err": { - "stack": "TypeError: boom\n at Object. (/Users/trentm/tm/node-bunyan/examples/err.js:15:9)\n at Module._compile (module.js:411:26)\n at Object..js (module.js:417:10)\n at Module.load (module.js:343:31)\n at Function._load (module.js:302:12)\n at Array.0 (module.js:430:10)\n at EventEmitter._tickCallback (node.js:126:26)", - "name": "TypeError", - "message": "boom" - }, - "level": 4, - "msg": "operation went boom: TypeError: boom", - "time": "2012-02-02T04:42:53.206Z", - "v": 0 -} -$ node err.js | ../bin/bunyan -[2012-02-02T05:02:39.412Z] WARN: myserver on banana.local: operation went boom: TypeError: boom - TypeError: boom - at Object. (/Users/trentm/tm/node-bunyan/examples/err.js:15:9) - at Module._compile (module.js:411:26) - at Object..js (module.js:417:10) - at Module.load (module.js:343:31) - at Function._load (module.js:302:12) - at Array.0 (module.js:430:10) - at EventEmitter._tickCallback (node.js:126:26) - -*/ +/* BEGIN JSSTYLED */ +/** + * + * $ node err.js | ../bin/bunyan -j + * { + * "name": "myserver", + * "hostname": "banana.local", + * "err": { + * "stack": "TypeError: boom\n at Object. (/Users/trentm/tm/node-bunyan/examples/err.js:15:9)\n at Module._compile (module.js:411:26)\n at Object..js (module.js:417:10)\n at Module.load (module.js:343:31)\n at Function._load (module.js:302:12)\n at Array.0 (module.js:430:10)\n at EventEmitter._tickCallback (node.js:126:26)", + * "name": "TypeError", + * "message": "boom" + * }, + * "level": 4, + * "msg": "operation went boom: TypeError: boom", + * "time": "2012-02-02T04:42:53.206Z", + * "v": 0 + * } + * $ node err.js | ../bin/bunyan + * [2012-02-02T05:02:39.412Z] WARN: myserver on banana.local: operation went boom: TypeError: boom + * TypeError: boom + * at Object. (/Users/trentm/tm/node-bunyan/examples/err.js:15:9) + * at Module._compile (module.js:411:26) + * at Object..js (module.js:417:10) + * at Module.load (module.js:343:31) + * at Function._load (module.js:302:12) + * at Array.0 (module.js:430:10) + * at EventEmitter._tickCallback (node.js:126:26) + * + */ +/* END JSSTYLED */ diff --git a/examples/handle-fs-error.js b/examples/handle-fs-error.js index 517999f..b0aa95b 100644 --- a/examples/handle-fs-error.js +++ b/examples/handle-fs-error.js @@ -34,4 +34,3 @@ setTimeout(function () { log.warn('warn log message'); console.warn('- Called log.warn(...).') }, 1000); - diff --git a/examples/hi.js b/examples/hi.js index 0afac83..0f5f21b 100644 --- a/examples/hi.js +++ b/examples/hi.js @@ -1,32 +1,32 @@ var Logger = require('../lib/bunyan'); // Basic usage. -var log = new Logger({name: "myapp", level: "info", src: true}); +var log = new Logger({name: 'myapp', level: 'info', src: true}); // isInfoEnabled replacement -console.log("log.info() is:", log.info()) +console.log('log.info() is:', log.info()) // `util.format`-based printf handling -log.info("hi"); -log.info("hi", "trent"); -log.info("hi %s there", true); +log.info('hi'); +log.info('hi', 'trent'); +log.info('hi %s there', true); // First arg as an object adds fields to the log record. -log.info({foo:"bar", multiline:"one\ntwo\nthree"}, "hi %d", 1, "two", 3); +log.info({foo:'bar', multiline:'one\ntwo\nthree'}, 'hi %d', 1, 'two', 3); // Shows `log.child(...)` to specialize a logger for a sub-component. -console.log("\n") +console.log('\n') function Wuzzle(options) { this.log = options.log; - this.log.info("creating a wuzzle") + this.log.info('creating a wuzzle') } Wuzzle.prototype.woos = function () { - this.log.warn("This wuzzle is woosey.") + this.log.warn('This wuzzle is woosey.') } -var wuzzle = new Wuzzle({log: log.child({component: "wuzzle"})}); +var wuzzle = new Wuzzle({log: log.child({component: 'wuzzle'})}); wuzzle.woos(); -log.info("done with the wuzzle") +log.info('done with the wuzzle') diff --git a/examples/level.js b/examples/level.js index 275d392..80bb563 100644 --- a/examples/level.js +++ b/examples/level.js @@ -37,11 +37,10 @@ try { assert.ok(e.message.indexOf('name') !== -1) } -log.trace("no one should see this") -log.debug("should see this once (on stdout)") -log.info("should see this twice") +log.trace('no one should see this') +log.debug('should see this once (on stdout)') +log.info('should see this twice') log.levels('stdout', INFO) -log.debug("no one should see this either") +log.debug('no one should see this either') log.level('trace') log.trace('should see this twice as 4th and 5th emitted log messages') - diff --git a/examples/multi.js b/examples/multi.js index 00a119e..81400ee 100644 --- a/examples/multi.js +++ b/examples/multi.js @@ -1,20 +1,20 @@ var Logger = require('../lib/bunyan'); log = new Logger({ - name: "amon", + name: 'amon', streams: [ { - level: "info", + level: 'info', stream: process.stdout, }, { - level: "error", - path: "multi.log" + level: 'error', + path: 'multi.log' } ] }); -log.debug("hi nobody on debug"); -log.info("hi stdout on info"); -log.error("hi both on error"); -log.fatal("hi both on fatal"); +log.debug('hi nobody on debug'); +log.info('hi stdout on info'); +log.error('hi both on error'); +log.fatal('hi both on fatal'); diff --git a/examples/server.js b/examples/server.js index 1acff65..c8bdac1 100644 --- a/examples/server.js +++ b/examples/server.js @@ -4,7 +4,7 @@ var http = require('http'); var Logger = require('../lib/bunyan'); var log = new Logger({ - name: "myserver", + name: 'myserver', serializers: { req: Logger.stdSerializers.req, res: Logger.stdSerializers.res @@ -12,13 +12,13 @@ var log = new Logger({ }); var server = http.createServer(function (req, res) { - log.info({req: req}, "start request"); // <-- this is the guy we're testing + log.info({req: req}, 'start request'); // <-- this is the guy we're testing res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); - log.info({res: res}, "done response"); // <-- this is the guy we're testing + log.info({res: res}, 'done response'); // <-- this is the guy we're testing }); -server.listen(1337, "127.0.0.1", function () { - log.info("server listening"); +server.listen(1337, '127.0.0.1', function () { + log.info('server listening'); var options = { port: 1337, hostname: '127.0.0.1', @@ -33,29 +33,31 @@ server.listen(1337, "127.0.0.1", function () { process.exit(); }) }); - req.write("hi from the client"); + req.write('hi from the client'); req.end(); }); -/* - -$ node server.js -{"service":"myserver","hostname":"banana.local","level":3,"msg":"server listening","time":"2012-02-02T05:32:13.257Z","v":0} -{"service":"myserver","hostname":"banana.local","req":{"method":"GET","url":"/path?q=1#anchor","headers":{"x-hi":"Mom","connection":"close"}},"level":3,"msg":"start request","time":"2012-02-02T05:32:13.260Z","v":0} -{"service":"myserver","hostname":"banana.local","res":{"statusCode":200,"_hasBody":true,"_header":"HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nConnection: close\r\nTransfer-Encoding: chunked\r\n\r\n","_trailer":""},"level":3,"msg":"done response","time":"2012-02-02T05:32:13.261Z","v":0} - -$ node server.js | ../bin/bunyan -[2012-02-02T05:32:16.006Z] INFO: myserver on banana.local: server listening -[2012-02-02T05:32:16.010Z] INFO: myserver on banana.local: start request - GET /path?q=1#anchor - x-hi: Mom - connection: close -[2012-02-02T05:32:16.011Z] INFO: myserver on banana.local: done response - HTTP/1.1 200 OK - Content-Type: text/plain - Connection: close - Transfer-Encoding: chunked - (body) - -*/ +/* BEGIN JSSTYLED */ +/** + * + * $ node server.js + * {"service":"myserver","hostname":"banana.local","level":3,"msg":"server listening","time":"2012-02-02T05:32:13.257Z","v":0} + * {"service":"myserver","hostname":"banana.local","req":{"method":"GET","url":"/path?q=1#anchor","headers":{"x-hi":"Mom","connection":"close"}},"level":3,"msg":"start request","time":"2012-02-02T05:32:13.260Z","v":0} + * {"service":"myserver","hostname":"banana.local","res":{"statusCode":200,"_hasBody":true,"_header":"HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nConnection: close\r\nTransfer-Encoding: chunked\r\n\r\n","_trailer":""},"level":3,"msg":"done response","time":"2012-02-02T05:32:13.261Z","v":0} + * + * $ node server.js | ../bin/bunyan + * [2012-02-02T05:32:16.006Z] INFO: myserver on banana.local: server listening + * [2012-02-02T05:32:16.010Z] INFO: myserver on banana.local: start request + * GET /path?q=1#anchor + * x-hi: Mom + * connection: close + * [2012-02-02T05:32:16.011Z] INFO: myserver on banana.local: done response + * HTTP/1.1 200 OK + * Content-Type: text/plain + * Connection: close + * Transfer-Encoding: chunked + * (body) + * + */ +/* END JSSTYLED */ diff --git a/examples/src.js b/examples/src.js index bb09e5a..fe4ab50 100644 --- a/examples/src.js +++ b/examples/src.js @@ -3,24 +3,23 @@ var Logger = require('../lib/bunyan'); -var log = new Logger({name: "src-example", src: true}); +var log = new Logger({name: 'src-example', src: true}); -log.info("one"); -log.info("two"); +log.info('one'); +log.info('two'); function doSomeFoo() { - log.info({foo:"bar"}, "three"); + log.info({foo:'bar'}, 'three'); } doSomeFoo(); function Wuzzle(options) { this.log = options.log; - this.log.info("creating a wuzzle") + this.log.info('creating a wuzzle') } Wuzzle.prototype.woos = function () { - this.log.warn("This wuzzle is woosey.") + this.log.warn('This wuzzle is woosey.') } -var wuzzle = new Wuzzle({log: log.child({component: "wuzzle"})}); +var wuzzle = new Wuzzle({log: log.child({component: 'wuzzle'})}); wuzzle.woos(); -log.info("done with the wuzzle") - +log.info('done with the wuzzle') diff --git a/examples/unstringifyable.js b/examples/unstringifyable.js index 4851e59..ddad545 100644 --- a/examples/unstringifyable.js +++ b/examples/unstringifyable.js @@ -1,7 +1,7 @@ // See how bunyan behaves with an un-stringify-able object. -var Logger = require("../lib/bunyan"); +var Logger = require('../lib/bunyan'); -var log = new Logger({src: true, name: "foo"}); +var log = new Logger({src: true, name: 'foo'}); // Make a circular object (cannot be JSON-ified). var myobj = { @@ -9,5 +9,4 @@ var myobj = { }; myobj.myobj = myobj; -log.info({obj: myobj}, "hi there"); // <--- here - +log.info({obj: myobj}, 'hi there'); // <--- here