From 83f33890dedac2192a72f9cb0b264da26c12ba32 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Sat, 17 Jan 2015 21:15:38 -0800 Subject: [PATCH] added integration with source-map-support for integration with sourcemaps Style updates, changelog, etc. Fixes #122 --- AUTHORS | 1 + CHANGES.md | 5 +++++ lib/bunyan.js | 10 ++++++++++ 3 files changed, 16 insertions(+) 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();