Skip to content

Commit

Permalink
- log.clone -> log.child to better reflect the relationship: stre…
Browse files Browse the repository at this point in the history
…ams and

  serializers are inherited. Streams can't be removed as part of the child
  creation. The child doesn't own the parent's streams (so can't close them).
- Clean up Logger creation. The goal here was to ensure `log.child` usage
  is fast. TODO: measure that.
- Add `Logger.stdSerializers.err` serializer which is necessary to get good
  Error object logging with node 0.6 (where core Error object properties
  are non-enumerable).
  • Loading branch information
trentm committed Feb 4, 2012
1 parent d123784 commit 6806112
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 165 deletions.
12 changes: 10 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# bunyan Changelog

## bunyan 0.2.1 (not yet released)
## bunyan 0.3.0 (not yet released)

- `log.clone` -> `log.child` to better reflect the relationship: streams and
serializers are inherited. Streams can't be removed as part of the child
creation. The child doesn't own the parent's streams (so can't close them).
- Clean up Logger creation. The goal here was to ensure `log.child` usage
is fast. TODO: measure that.
- Add `Logger.stdSerializers.err` serializer which is necessary to get good
Error object logging with node 0.6 (where core Error object properties
are non-enumerable).

(nothing yet)

## bunyan 0.2.0

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ follow (feedback from actual users welcome).
Recommended/Best Practice Fields:

- `err`: Object. A caught JS exception. Log that thing with
`log.error({err: err}, "oops")`! JS exceptions `JSON.stringify` quite
nicely so you don't need to do anything else. See "examples/err.js".
`log.error({err: err}, "oops")` and **use the `Logger.stdSerializers.err`**
serializer for it. See "examples/err.js".
- `req_id`: String. A request identifier. Including this field in all logging
tied to handling a particular request to your server is strongly suggested.
This allows post analysis of logs to easily collate all related logging
Expand Down
10 changes: 2 additions & 8 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
- expand set of fields: from dap
time, hostname
<https://github.com/Graylog2/graylog2-docs/wiki/GELF>
<http://journal.paul.querna.org/articles/2011/12/26/log-for-machines-in-json/>
require: facility and hostname
line/file: possible to get quickly with v8? Yunong asked.
- fast clone: basically make it reasonable to clone per HTTP request.
Ditch mutability. Add another context (another entry in Log record tuple?)?
- `log.close` to close streams and shutdown and `this.closed`
- line/file: possible to get quickly with v8? Yunong asked.
- what's the API for changing the logger/stream level(s)?
- bunyan cli: more layouts (http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/EnhancedPatternLayout.html)
Custom log formats (in config file? in '-f' arg) using printf or hogan.js
or whatever. Dap wants field width control for lining up. Hogan.js is
Expand All @@ -28,8 +24,6 @@
}
- Logger.setLevel()? How to change level for a given stream. Default all,
else, give an index... or type ... or support stream "names".
- Logger.set to mutate config or `this.fields`
- Logger.del to remove a field
- "canWrite" handling for full streams. Need to buffer a la log4js
- test file log with logadm rotation: does it handle that?
- test suite:
Expand Down
2 changes: 1 addition & 1 deletion bin/bunyan
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// See <https://github.com/trentm/node-bunyan>.
//

var VERSION = "0.2.1";
var VERSION = "0.3.0";

var util = require('util');
var pathlib = require('path');
Expand Down
5 changes: 3 additions & 2 deletions examples/err.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

var http = require('http');
var Logger = require('../lib/bunyan');
var util = require('util');

var log = new Logger({
service: "myserver",
serializers: {
req: Logger.stdSerializers.req,
res: Logger.stdSerializers.res
err: Logger.stdSerializers.err, // <--- use this
}
});

Expand All @@ -25,6 +25,7 @@ $ node err.js | ../bin/bunyan -j
"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,
Expand Down
4 changes: 2 additions & 2 deletions examples/hi.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ log.info("hi %s there", true);
log.info({foo:"bar"}, "hi %d", 1, "two", 3);


// Shows `log.clone(...)` to specialize a logger for a sub-component.
// Shows `log.child(...)` to specialize a logger for a sub-component.
console.log("\n\n")

function Wuzzle(options) {
Expand All @@ -27,7 +27,7 @@ Wuzzle.prototype.woos = function () {
this.log.warn("This wuzzle is woosey.")
}

var wuzzle = new Wuzzle({log: log.clone({component: "wuzzle"})});
var wuzzle = new Wuzzle({log: log.child({component: "wuzzle"})});
wuzzle.woos();
log.info("done with the wuzzle")

Loading

0 comments on commit 6806112

Please sign in to comment.