Permalink
Browse files

GH-958 RequestCaptureStream now writes triggering record

  • Loading branch information...
1 parent ffc3abe commit 5425d4d1e26094f14784e9ee90ad010fe14a44eb @yunong yunong committed May 12, 2016
Showing with 65 additions and 10 deletions.
  1. +12 −0 .tern-project
  2. +5 −6 lib/bunyan_helper.js
  3. +2 −2 test/lib/helper.js
  4. +46 −2 test/server.test.js
View
@@ -0,0 +1,12 @@
+{
+ "libs": [
+ "ecma5",
+ "chai"
+ ],
+ "plugins": {
+ "node": {},
+ "complete_strings": {},
+ "doc_comment": {},
+ "node_resolve": {}
+ }
+}
View
@@ -146,15 +146,17 @@ RequestCaptureStream.prototype.write = function write(record) {
assert.ok(ring, 'no ring found');
+ // write the record to the ring.
+ ring.write(record);
+ // triger dumping of all the records
if (record.level >= this.level) {
var i, r, ser;
for (i = 0; i < ring.records.length; i++) {
r = ring.records[i];
if (this.haveNonRawStreams) {
- ser = JSON.stringify(r,
- bunyan.safeCycles()) + '\n';
+ ser = JSON.stringify(r, bunyan.safeCycles()) + '\n';
}
self.streams.forEach(function (s) {
s.stream.write(s.raw ? r : ser);
@@ -169,17 +171,14 @@ RequestCaptureStream.prototype.write = function write(record) {
r = defaultRing.records[i];
if (this.haveNonRawStreams) {
- ser = JSON.stringify(r,
- bunyan.safeCycles()) + '\n';
+ ser = JSON.stringify(r, bunyan.safeCycles()) + '\n';
}
self.streams.forEach(function (s) {
s.stream.write(s.raw ? r : ser);
});
}
defaultRing.records.length = 0;
}
- } else {
- ring.write(record);
}
};
View
@@ -75,11 +75,11 @@ module.exports = {
};
},
- getLog: function (name, stream, level) {
+ getLog: function (name, streams, level) {
return (bunyan.createLogger({
level: (process.env.LOG_LEVEL || level || 'fatal'),
name: name || process.argv[1],
- stream: stream || process.stdout,
+ streams: streams || [{stream: process.stdout}],
src: true,
serializers: restify.bunyan.serializers
}));
View
@@ -6,6 +6,7 @@ var assert = require('assert-plus');
var bunyan = require('bunyan');
var childprocess = require('child_process');
var http = require('http');
+var stream = require('stream');
var errors = require('restify-errors');
var filed = require('filed');
@@ -2029,7 +2030,7 @@ test('GH-667 emit error event for generic Errors', function (t) {
return cb();
});
- /* eslint-disable no-shadow */
+ /*eslint-disable no-shadow*/
CLIENT.get('/1', function (err, req, res, data) {
// should get regular error
t.ok(err);
@@ -2048,7 +2049,7 @@ test('GH-667 emit error event for generic Errors', function (t) {
});
});
});
- /* eslint-enable no-shadow */
+ /*eslint-enable no-shadow*/
});
@@ -2073,6 +2074,49 @@ function (t) {
});
+test('GH-958 RCS does not write triggering record', function (t) {
+ var passThrough = new stream.PassThrough();
+ var count = 1;
+ // we would expect to get 3 logging statements
+ passThrough.on('data', function (chunk) {
+ var obj = JSON.parse(chunk.toString());
+ t.equal(obj.msg, count.toString());
+
+ if (count === 3) {
+ t.end();
+ }
+ count++;
+ });
+
+ SERVER.log = helper.getLog(
+ 'server', [{
+ level: bunyan.DEBUG,
+ type: 'raw',
+ stream: new restify.bunyan.RequestCaptureStream({
+ level: bunyan.WARN,
+ stream: passThrough
+ })}
+ ]
+ );
+
+ SERVER.use(plugins.requestLogger());
+
+ SERVER.get('/rcs', function (req, res, next) {
+ req.log.debug('1');
+ req.log.info('2');
+ req.log.error('3');
+ res.send();
+ next();
+ });
+
+ CLIENT.get('/rcs', function (err, _, res) {
+ console.log('client');
+ t.ifError(err);
+ t.equal(res.statusCode, 200);
+ });
+});
+
+
test('GH-1024 disable uncaughtException handler', function (t) {
// With uncaughtException handling disabled, the node process will abort,
// so testing of this feature must occur in a separate node process.

0 comments on commit 5425d4d

Please sign in to comment.