Fix src: true, which was broken in v1.5.0.

Also add a test case for `src: true` which is how 1.5.0 got released
without noticing this.

Fixes #296.
This commit is contained in:
Trent Mick 2015-09-07 14:37:29 -07:00
parent 2975178220
commit 86b6769087
3 changed files with 77 additions and 10 deletions

View file

@ -8,11 +8,14 @@ Known issues:
## bunyan 1.5.1 (not yet released)
(nothing yet)
- [issue #296] Fix `src: true`, which was broken in v1.5.0.
## bunyan 1.5.0
Note: *Bad release.* The addition of `'use strict';` broke Bunyan's `src: true`
feature. Use 1.5.1 instead.
- [pull #236, issue #231, issue #223] Fix strict mode in the browser.
- [pull #282, issue #213] Fixes bunyan to work with webpack. By Denis Izmaylov.
- [pull #294] Update to dtrace-provider 0.6 to fix with node 4.0 and io.js 3.0.

View file

@ -1,6 +1,6 @@
/**
* Copyright (c) 2014 Trent Mick. All rights reserved.
* Copyright (c) 2014 Joyent Inc. All rights reserved.
* Copyright (c) 2015 Trent Mick.
* Copyright (c) 2015 Joyent Inc.
*
* The bunyan logging library for node.js.
*
@ -8,15 +8,13 @@
* vim: expandtab:ts=4:sw=4
*/
'use strict';
var VERSION = '1.5.1';
// Bunyan log format version. This becomes the 'v' field on all log records.
// `0` is until I release a version '1.0.0' of node-bunyan. Thereafter,
// starting with `1`, this will be incremented if there is any backward
// incompatible change to the log record format. Details will be in
// 'CHANGES.md' (the change log).
/*
* Bunyan log format version. This becomes the 'v' field on all log records.
* This will be incremented if there is any backward incompatible change to
* the log record format. Details will be in 'CHANGES.md' (the change log).
*/
var LOG_VERSION = 0;
@ -149,6 +147,10 @@ if (!format) {
* See <http://code.google.com/p/v8/wiki/JavaScriptStackTraceApi>.
*/
function getCaller3Info() {
if (this === undefined) {
// Cannot access caller info in 'strict' mode.
return;
}
var obj = {};
var saveLimit = Error.stackTraceLimit;
var savePrepare = Error.prepareStackTrace;

62
test/src.test.js Normal file
View file

@ -0,0 +1,62 @@
/*
* Copyright (c) 2015 Trent Mick.
*
* Test `src: true` usage.
*/
// Intentionally on line 8 for tests below:
function logSomething(log) { log.info('something'); }
var format = require('util').format;
var Logger = require('../lib/bunyan');
// node-tap API
if (require.cache[__dirname + '/tap4nodeunit.js'])
delete require.cache[__dirname + '/tap4nodeunit.js'];
var tap4nodeunit = require('./tap4nodeunit.js');
var after = tap4nodeunit.after;
var before = tap4nodeunit.before;
var test = tap4nodeunit.test;
function CapturingStream(recs) {
this.recs = recs;
}
CapturingStream.prototype.write = function (rec) {
this.recs.push(rec);
}
test('src', function (t) {
var recs = [];
var log = new Logger({
name: 'src-test',
src: true,
streams: [
{
stream: new CapturingStream(recs),
type: 'raw'
}
]
});
log.info('top-level');
logSomething(log);
t.equal(recs.length, 2);
recs.forEach(function (rec) {
t.ok(rec.src);
t.equal(typeof (rec.src), 'object');
t.equal(rec.src.file, __filename);
t.ok(rec.src.line);
t.equal(typeof (rec.src.line), 'number');
});
var rec = recs[1];
t.ok(rec.src.func);
t.equal(rec.src.func, 'logSomething');
t.equal(rec.src.line, 8);
t.end();
});