diff --git a/AUTHORS b/AUTHORS index 526ba14..01bf371 100644 --- a/AUTHORS +++ b/AUTHORS @@ -18,3 +18,4 @@ Andrei Neculau (https://github.com/andreineculau) Mihai Tomescu (https://github.com/matomesc) Daniel Juhl (https://github.com/danieljuhl) Chris Barber (https://github.com/cb1kenobi) +Manuel Schneider (https://github.com/manuelschneider) diff --git a/CHANGES.md b/CHANGES.md index 374c42a..5eab482 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,6 +8,11 @@ Known issues: ## bunyan 1.3.1 (not yet released) +- [pull #122] Source Map support for caller line position for [the "src" + field](https://github.com/trentm/node-bunyan#src). This could be interesting + for [CoffeeScript](http://coffeescript.org/documentation/docs/sourcemap.html) + users of Bunyan. By Manuel Schneider. + - [issue #164] Ensure a top-level `level` given in `bunyan.createLogger` is *used* for given `streams`. For example, ensure that the following results in the stream having a DEBUG level: diff --git a/lib/bunyan.js b/lib/bunyan.js index 43533f0..51c7521 100644 --- a/lib/bunyan.js +++ b/lib/bunyan.js @@ -50,6 +50,12 @@ try { var isBrowser = function () { return typeof (window) !== 'undefined' && this === window; }(); +try { + var sourceMapSupport = require("source-map-support"); +} catch (_) { + sourceMapSupport = null; +} + //---- Internal support stuff @@ -126,8 +132,12 @@ function getCaller3Info() { var savePrepare = Error.prepareStackTrace; Error.stackTraceLimit = 3; Error.captureStackTrace(this, getCaller3Info); + Error.prepareStackTrace = function (_, stack) { var caller = stack[2]; + if (sourceMapSupport) { + caller = sourceMapSupport.wrapCallSite(caller); + } obj.file = caller.getFileName(); obj.line = caller.getLineNumber(); var func = caller.getFunctionName();