jsstyling of example files

This commit is contained in:
Trent Mick 2012-06-04 23:19:39 -07:00
parent 858150bbd2
commit bb8664a559
9 changed files with 99 additions and 99 deletions

View file

@ -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")

View file

@ -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.<anonymous> (/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.<anonymous> (/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.<anonymous> (/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.<anonymous> (/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 */

View file

@ -34,4 +34,3 @@ setTimeout(function () {
log.warn('warn log message');
console.warn('- Called log.warn(...).')
}, 1000);

View file

@ -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')

View file

@ -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')

View file

@ -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');

View file

@ -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 */

View file

@ -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')

View file

@ -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