jsstyling of example files
This commit is contained in:
parent
858150bbd2
commit
bb8664a559
9 changed files with 99 additions and 99 deletions
2
Makefile
2
Makefile
|
@ -6,7 +6,7 @@ TAP := ./node_modules/.bin/tap
|
||||||
|
|
||||||
#---- Files
|
#---- Files
|
||||||
|
|
||||||
JSSTYLE_FILES := $(shell find lib test tools -name "*.js")
|
JSSTYLE_FILES := $(shell find lib test tools examples -name "*.js")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,52 +5,54 @@ var Logger = require('../lib/bunyan');
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
|
|
||||||
var log = new Logger({
|
var log = new Logger({
|
||||||
name: "myserver",
|
name: 'myserver',
|
||||||
serializers: {
|
serializers: {
|
||||||
err: Logger.stdSerializers.err, // <--- use this
|
err: Logger.stdSerializers.err, // <--- use this
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
throw new TypeError("boom");
|
throw new TypeError('boom');
|
||||||
} catch (err) {
|
} 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 {
|
try {
|
||||||
throw "boom string";
|
throw 'boom string';
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log.error(err)
|
log.error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/* BEGIN JSSTYLED */
|
||||||
|
/**
|
||||||
$ node err.js | ../bin/bunyan -j
|
*
|
||||||
{
|
* $ node err.js | ../bin/bunyan -j
|
||||||
"name": "myserver",
|
* {
|
||||||
"hostname": "banana.local",
|
* "name": "myserver",
|
||||||
"err": {
|
* "hostname": "banana.local",
|
||||||
"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)",
|
* "err": {
|
||||||
"name": "TypeError",
|
* "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)",
|
||||||
"message": "boom"
|
* "name": "TypeError",
|
||||||
},
|
* "message": "boom"
|
||||||
"level": 4,
|
* },
|
||||||
"msg": "operation went boom: TypeError: boom",
|
* "level": 4,
|
||||||
"time": "2012-02-02T04:42:53.206Z",
|
* "msg": "operation went boom: TypeError: boom",
|
||||||
"v": 0
|
* "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
|
* $ node err.js | ../bin/bunyan
|
||||||
TypeError: boom
|
* [2012-02-02T05:02:39.412Z] WARN: myserver on banana.local: operation went boom: TypeError: boom
|
||||||
at Object.<anonymous> (/Users/trentm/tm/node-bunyan/examples/err.js:15:9)
|
* TypeError: boom
|
||||||
at Module._compile (module.js:411:26)
|
* at Object.<anonymous> (/Users/trentm/tm/node-bunyan/examples/err.js:15:9)
|
||||||
at Object..js (module.js:417:10)
|
* at Module._compile (module.js:411:26)
|
||||||
at Module.load (module.js:343:31)
|
* at Object..js (module.js:417:10)
|
||||||
at Function._load (module.js:302:12)
|
* at Module.load (module.js:343:31)
|
||||||
at Array.0 (module.js:430:10)
|
* at Function._load (module.js:302:12)
|
||||||
at EventEmitter._tickCallback (node.js:126:26)
|
* at Array.0 (module.js:430:10)
|
||||||
|
* at EventEmitter._tickCallback (node.js:126:26)
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
/* END JSSTYLED */
|
||||||
|
|
|
@ -34,4 +34,3 @@ setTimeout(function () {
|
||||||
log.warn('warn log message');
|
log.warn('warn log message');
|
||||||
console.warn('- Called log.warn(...).')
|
console.warn('- Called log.warn(...).')
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
|
|
|
@ -1,32 +1,32 @@
|
||||||
var Logger = require('../lib/bunyan');
|
var Logger = require('../lib/bunyan');
|
||||||
|
|
||||||
// Basic usage.
|
// Basic usage.
|
||||||
var log = new Logger({name: "myapp", level: "info", src: true});
|
var log = new Logger({name: 'myapp', level: 'info', src: true});
|
||||||
|
|
||||||
// isInfoEnabled replacement
|
// isInfoEnabled replacement
|
||||||
console.log("log.info() is:", log.info())
|
console.log('log.info() is:', log.info())
|
||||||
|
|
||||||
// `util.format`-based printf handling
|
// `util.format`-based printf handling
|
||||||
log.info("hi");
|
log.info('hi');
|
||||||
log.info("hi", "trent");
|
log.info('hi', 'trent');
|
||||||
log.info("hi %s there", true);
|
log.info('hi %s there', true);
|
||||||
|
|
||||||
// First arg as an object adds fields to the log record.
|
// 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.
|
// Shows `log.child(...)` to specialize a logger for a sub-component.
|
||||||
console.log("\n")
|
console.log('\n')
|
||||||
|
|
||||||
function Wuzzle(options) {
|
function Wuzzle(options) {
|
||||||
this.log = options.log;
|
this.log = options.log;
|
||||||
this.log.info("creating a wuzzle")
|
this.log.info('creating a wuzzle')
|
||||||
}
|
}
|
||||||
|
|
||||||
Wuzzle.prototype.woos = function () {
|
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();
|
wuzzle.woos();
|
||||||
log.info("done with the wuzzle")
|
log.info('done with the wuzzle')
|
||||||
|
|
|
@ -37,11 +37,10 @@ try {
|
||||||
assert.ok(e.message.indexOf('name') !== -1)
|
assert.ok(e.message.indexOf('name') !== -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.trace("no one should see this")
|
log.trace('no one should see this')
|
||||||
log.debug("should see this once (on stdout)")
|
log.debug('should see this once (on stdout)')
|
||||||
log.info("should see this twice")
|
log.info('should see this twice')
|
||||||
log.levels('stdout', INFO)
|
log.levels('stdout', INFO)
|
||||||
log.debug("no one should see this either")
|
log.debug('no one should see this either')
|
||||||
log.level('trace')
|
log.level('trace')
|
||||||
log.trace('should see this twice as 4th and 5th emitted log messages')
|
log.trace('should see this twice as 4th and 5th emitted log messages')
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,20 @@
|
||||||
var Logger = require('../lib/bunyan');
|
var Logger = require('../lib/bunyan');
|
||||||
log = new Logger({
|
log = new Logger({
|
||||||
name: "amon",
|
name: 'amon',
|
||||||
streams: [
|
streams: [
|
||||||
{
|
{
|
||||||
level: "info",
|
level: 'info',
|
||||||
stream: process.stdout,
|
stream: process.stdout,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
level: "error",
|
level: 'error',
|
||||||
path: "multi.log"
|
path: 'multi.log'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
log.debug("hi nobody on debug");
|
log.debug('hi nobody on debug');
|
||||||
log.info("hi stdout on info");
|
log.info('hi stdout on info');
|
||||||
log.error("hi both on error");
|
log.error('hi both on error');
|
||||||
log.fatal("hi both on fatal");
|
log.fatal('hi both on fatal');
|
||||||
|
|
|
@ -4,7 +4,7 @@ var http = require('http');
|
||||||
var Logger = require('../lib/bunyan');
|
var Logger = require('../lib/bunyan');
|
||||||
|
|
||||||
var log = new Logger({
|
var log = new Logger({
|
||||||
name: "myserver",
|
name: 'myserver',
|
||||||
serializers: {
|
serializers: {
|
||||||
req: Logger.stdSerializers.req,
|
req: Logger.stdSerializers.req,
|
||||||
res: Logger.stdSerializers.res
|
res: Logger.stdSerializers.res
|
||||||
|
@ -12,13 +12,13 @@ var log = new Logger({
|
||||||
});
|
});
|
||||||
|
|
||||||
var server = http.createServer(function (req, res) {
|
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.writeHead(200, {'Content-Type': 'text/plain'});
|
||||||
res.end('Hello World\n');
|
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 () {
|
server.listen(1337, '127.0.0.1', function () {
|
||||||
log.info("server listening");
|
log.info('server listening');
|
||||||
var options = {
|
var options = {
|
||||||
port: 1337,
|
port: 1337,
|
||||||
hostname: '127.0.0.1',
|
hostname: '127.0.0.1',
|
||||||
|
@ -33,29 +33,31 @@ server.listen(1337, "127.0.0.1", function () {
|
||||||
process.exit();
|
process.exit();
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
req.write("hi from the client");
|
req.write('hi from the client');
|
||||||
req.end();
|
req.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*
|
/* BEGIN JSSTYLED */
|
||||||
|
/**
|
||||||
$ node server.js
|
*
|
||||||
{"service":"myserver","hostname":"banana.local","level":3,"msg":"server listening","time":"2012-02-02T05:32:13.257Z","v":0}
|
* $ node server.js
|
||||||
{"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","level":3,"msg":"server listening","time":"2012-02-02T05:32:13.257Z","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}
|
* {"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
|
* $ node server.js | ../bin/bunyan
|
||||||
[2012-02-02T05:32:16.010Z] INFO: myserver on banana.local: start request
|
* [2012-02-02T05:32:16.006Z] INFO: myserver on banana.local: server listening
|
||||||
GET /path?q=1#anchor
|
* [2012-02-02T05:32:16.010Z] INFO: myserver on banana.local: start request
|
||||||
x-hi: Mom
|
* GET /path?q=1#anchor
|
||||||
connection: close
|
* x-hi: Mom
|
||||||
[2012-02-02T05:32:16.011Z] INFO: myserver on banana.local: done response
|
* connection: close
|
||||||
HTTP/1.1 200 OK
|
* [2012-02-02T05:32:16.011Z] INFO: myserver on banana.local: done response
|
||||||
Content-Type: text/plain
|
* HTTP/1.1 200 OK
|
||||||
Connection: close
|
* Content-Type: text/plain
|
||||||
Transfer-Encoding: chunked
|
* Connection: close
|
||||||
(body)
|
* Transfer-Encoding: chunked
|
||||||
|
* (body)
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
|
/* END JSSTYLED */
|
||||||
|
|
|
@ -3,24 +3,23 @@
|
||||||
|
|
||||||
var Logger = require('../lib/bunyan');
|
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('one');
|
||||||
log.info("two");
|
log.info('two');
|
||||||
function doSomeFoo() {
|
function doSomeFoo() {
|
||||||
log.info({foo:"bar"}, "three");
|
log.info({foo:'bar'}, 'three');
|
||||||
}
|
}
|
||||||
doSomeFoo();
|
doSomeFoo();
|
||||||
|
|
||||||
function Wuzzle(options) {
|
function Wuzzle(options) {
|
||||||
this.log = options.log;
|
this.log = options.log;
|
||||||
this.log.info("creating a wuzzle")
|
this.log.info('creating a wuzzle')
|
||||||
}
|
}
|
||||||
Wuzzle.prototype.woos = function () {
|
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();
|
wuzzle.woos();
|
||||||
log.info("done with the wuzzle")
|
log.info('done with the wuzzle')
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// See how bunyan behaves with an un-stringify-able object.
|
// 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).
|
// Make a circular object (cannot be JSON-ified).
|
||||||
var myobj = {
|
var myobj = {
|
||||||
|
@ -9,5 +9,4 @@ var myobj = {
|
||||||
};
|
};
|
||||||
myobj.myobj = myobj;
|
myobj.myobj = myobj;
|
||||||
|
|
||||||
log.info({obj: myobj}, "hi there"); // <--- here
|
log.info({obj: myobj}, 'hi there'); // <--- here
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue