Comparing version 0.3.0 to 0.4.0
# bunyan Changelog | ||
## bunyan 0.4.0 | ||
- Add `new Logger({src: true})` config option to have a 'src' attribute be | ||
automatically added to log records with the log call source info. Example: | ||
"src": { | ||
"file": "/Users/trentm/tm/node-bunyan/examples/src.js", | ||
"line": 20, | ||
"func": "Wuzzle.woos" | ||
}, | ||
## bunyan 0.3.0 | ||
@@ -4,0 +16,0 @@ |
@@ -5,3 +5,3 @@ /* | ||
var VERSION = "0.3.0"; | ||
var VERSION = "0.4.0"; | ||
@@ -86,3 +86,29 @@ // Bunyan log format version. This becomes the 'v' field on all log records. | ||
/** | ||
* Gather some caller info 3 stack levels up. | ||
* See <http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi>. | ||
*/ | ||
function getCaller3Info() { | ||
var obj = {}; | ||
var saveLimit = Error.stackTraceLimit; | ||
var savePrepare = Error.prepareStackTrace; | ||
Error.stackTraceLimit = 3; | ||
Error.captureStackTrace(this, getCaller3Info); | ||
Error.prepareStackTrace = function(_, stack) { | ||
var caller = stack[2]; | ||
obj.file = caller.getFileName(); | ||
obj.line = caller.getLineNumber(); | ||
var func = caller.getFunctionName(); | ||
if (func) | ||
obj.func = func; | ||
}; | ||
this.stack; | ||
Error.stackTraceLimit = saveLimit; | ||
Error.prepareStackTrace = savePrepare; | ||
return obj; | ||
} | ||
//---- Levels | ||
@@ -140,2 +166,4 @@ | ||
* serializing functions. See README.md for details. | ||
* - `src`: Boolean (default false). Set true to enable 'src' automatic | ||
* field with log call source info. | ||
* All other keys are log record fields. | ||
@@ -182,2 +210,3 @@ * | ||
this.serializers = parent.serializers; | ||
this.src = parent.src; | ||
this.fields = parent.fields; | ||
@@ -203,2 +232,3 @@ var names = Object.keys(options); | ||
this.serializers = objCopy(parent.serializers); | ||
this.src = parent.src; | ||
this.fields = objCopy(parent.fields); | ||
@@ -209,2 +239,3 @@ } else { | ||
this.serializers = null; | ||
this.src = false; | ||
this.fields = {}; | ||
@@ -298,2 +329,5 @@ } | ||
} | ||
if (options.src) { | ||
this.src = true; | ||
} | ||
xxx("Logger: ", self) | ||
@@ -311,2 +345,3 @@ | ||
delete fields.serializers; | ||
delete fields.src; | ||
if (this.serializers) { | ||
@@ -454,4 +489,8 @@ this._applySerializers(fields); | ||
} | ||
// Get call source info | ||
if (this.src && !obj.src) { | ||
obj.src = getCaller3Info() | ||
} | ||
obj.v = LOG_VERSION; | ||
xxx('_emit: stringify this:', obj); | ||
@@ -458,0 +497,0 @@ var str = JSON.stringify(obj) + '\n'; |
{ | ||
"name": "bunyan", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "a JSON Logger library for node.js servers", | ||
@@ -5,0 +5,0 @@ "main": "./lib/bunyan.js", |
@@ -35,3 +35,13 @@ Bunyan -- a JSON Logger for node.js servers. | ||
A **`bunyan` tool is provided for pretty-printing** bunyan logs and, eventually, | ||
The full `log.{trace|debug|...|fatal}(...)` API is: | ||
log.info(); // returns a boolean: is the "info" level enabled? | ||
log.info("hi"); // log a simple string message | ||
log.info("hi %s", bob, anotherVar); // uses `util.format` for msg formatting | ||
log.info({foo: "bar"}, "hi"); // adds "foo" field to log record | ||
## bunyan tool | ||
A `bunyan` tool is provided **for pretty-printing bunyan logs** and, eventually, | ||
for filtering (e.g. `| bunyan -c 'level>3'`). This shows the default output | ||
@@ -54,2 +64,5 @@ (which is fluid right now) and indented-JSON output. More output formats will | ||
## streams | ||
By default, log output is to stdout (**stream**) and at the "info" level. | ||
@@ -78,3 +91,6 @@ Explicitly that looks like: | ||
A **`log.child(...)`** is provided to specialize a logger for a sub-component. | ||
## log.child | ||
A `log.child(...)` is provided to **specialize a logger for a sub-component**. | ||
The following will have log records from "Wuzzle" instances use exactly the | ||
@@ -99,6 +115,7 @@ same config as its parent, plus include the "component" field. | ||
* * * | ||
An example and a hack: The [node-restify](https://github.com/mcavage/node-restify) | ||
framework integrates bunyan. One feature is that each restify request handler | ||
includes a `req.log` logger that is a: | ||
includes a `req.log` logger that is: | ||
@@ -108,15 +125,12 @@ log.child({req_id: <unique request id>}, true) | ||
Apps using restify can then use `req.log` and have all such log records | ||
include the unique request id (as "req_id"). Handy. *What is that `true`?* It | ||
is a small bunyan hack by which you can assert that you're just adding | ||
simple fields to the child logger. This makes `log.child` 10x faster and, | ||
hence, never a worry for slowing down HTTP request handling. See the | ||
changelog for node-bunyan 0.3.0 for details. | ||
include the unique request id (as "req_id"). Handy. | ||
*What is that `true`?* It is a small bunyan hack by which you can assert that | ||
you're just adding simple fields to the child logger. This makes `log.child` | ||
10x faster and, hence, never a worry for slowing down HTTP request handling. | ||
See the changelog for node-bunyan 0.3.0 for details. | ||
Back to the `log.{trace|debug|...|fatal}(...)` API: | ||
* * * | ||
log.info(); // returns a boolean: is the "info" level enabled? | ||
log.info("hi"); // log a simple string message | ||
log.info("hi %s", bob, anotherVar); // uses `util.format` for msg formatting | ||
log.info({foo: "bar"}, "hi"); // adds "foo" field to log record | ||
## serializers | ||
@@ -164,22 +178,30 @@ Bunyan has a concept of **"serializers" to produce a JSON-able object from a | ||
## src | ||
The **call source file, line and function** (if not at the global level) can | ||
be added to log records by using the `src: true` config option: | ||
# Future | ||
var log = new Logger({src: true, ...}); | ||
See "TODO.md", but basically: | ||
This adds the call source info with the 'src' field, like this: | ||
- More std serializers. See TODO.md. | ||
{ | ||
"service": "src-example", | ||
"hostname": "banana.local", | ||
"component": "wuzzle", | ||
"level": 4, | ||
"msg": "This wuzzle is woosey.", | ||
"time": "2012-02-06T04:19:35.605Z", | ||
"src": { | ||
"file": "/Users/trentm/tm/node-bunyan/examples/src.js", | ||
"line": 20, | ||
"func": "Wuzzle.woos" | ||
}, | ||
"v": 0 | ||
} | ||
- Spec'ing and enforcing the fields (from dap's section in eng guide). | ||
**WARNING: Determining the call source info is slow. Never use this option | ||
in production.** | ||
- Syslog support. Ring-buffer support for storing last N debug messages | ||
(or whatever) in memory to support debugability without too much log load. | ||
- More `bunyan` output formats and filtering features. | ||
- Think about a bunyan dashboard that supports organizing and viewing logs | ||
from multiple hosts and services. | ||
# Levels | ||
@@ -268,2 +290,5 @@ | ||
Every `log.debug(...)` et al call must provide a log message. | ||
- `src`: Optional. Object giving log call source info. This is added | ||
automatically by Bunyan if the "src: true" config option is given to the | ||
Logger. Never use in production as this is really slow. | ||
@@ -338,1 +363,19 @@ | ||
# Future | ||
See "TODO.md", but basically: | ||
- Ring-buffer support for storing last N debug messages | ||
(or whatever) in memory to support debugability without too much log load. | ||
- More `bunyan` output formats and filtering features. | ||
- Think about a bunyan dashboard that supports organizing and viewing logs | ||
from multiple hosts and services. | ||
- Syslog support. | ||
- Some speed comparisons with others to get a feel for Bunyan's speed. | ||
46
TODO.md
@@ -1,4 +0,6 @@ | ||
- `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)? | ||
file/line/func (?) | ||
- Logger.setLevel()? How to change level for a given stream. Default all, | ||
else, give an index... or type ... or support stream "names". Some positives | ||
to stream names. | ||
- bunyan cli: more layouts (http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/EnhancedPatternLayout.html) | ||
@@ -8,6 +10,2 @@ Custom log formats (in config file? in '-f' arg) using printf or hogan.js | ||
probably overkill for this. | ||
- bunyan cli: filter args a la json | ||
- bunyan cli: -c COND args a la json | ||
- mark wants pretty output for debug output | ||
- not sure if 'bunyan --pretty' or whatever would suffice | ||
- ringBuffer stream | ||
@@ -24,4 +22,2 @@ - syslog: Josh uses https://github.com/chrisdew/node-syslog | ||
} | ||
- Logger.setLevel()? How to change level for a given stream. Default all, | ||
else, give an index... or type ... or support stream "names". | ||
- "canWrite" handling for full streams. Need to buffer a la log4js | ||
@@ -37,2 +33,10 @@ - test file log with logadm rotation: does it handle that? | ||
requested) | ||
- (mark) instanceof-based serialization: | ||
log.info(new Error("blah blah")) -> {err: ..., msg: ""} | ||
perhaps at least default for Error. Then perhaps augment or replace | ||
serializers with registerable instanceof's. | ||
log = new Logger({ | ||
serializers | ||
}) | ||
@@ -42,22 +46,8 @@ | ||
- file/line fields automatic: "but it's fucking slow" (https://gist.github.com/1733234) | ||
function getFileAndLine() { | ||
var self = this; | ||
var saveLimit = Error.stackTraceLimit; | ||
var savePrepare = Error.prepareStackTrace; | ||
Error.stackTraceLimit = 1; | ||
Error.captureStackTrace(this, getFileAndLine); | ||
Error.prepareStackTrace = function(_, stack) { | ||
self.file = stack[0].getFileName(); | ||
self.line = stack[0].getLineNumber(); | ||
}; | ||
this.stack; | ||
Error.stackTraceLimit = saveLimit; | ||
Error.prepareStackTrace = savePrepare; | ||
return { | ||
file: self.file, | ||
line: self.line | ||
} | ||
} | ||
Want some way to have file/line only at certain levesl and lazily. | ||
- bunyan cli: filter args a la json | ||
- bunyan cli: -c COND args a la json | ||
- bunyan "compact" or "light", '-l'? Something like. Or pehaps this (with | ||
color) could be the default, with '-l' for long output. | ||
13:51.340 [src.js:20#Wuzzle.woos] WARN: This wuzzle is woosey. | ||
- `log.close` to close streams and shutdown and `this.closed` | ||
- get Mark to show me dtrace provider stuff and consider adding for | ||
@@ -64,0 +54,0 @@ logging, if helpful. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
220715
59
4577
374