Skip to content

Commit

Permalink
Add responseSentTime to response format (#95)
Browse files Browse the repository at this point in the history
* Add responseSentTime to response format

* Add label before response times

* Update dev deps
  • Loading branch information
berzniz authored and arb committed Jan 10, 2018
1 parent 26b1fc2 commit eb54cd1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lib/index.js
Expand Up @@ -82,10 +82,10 @@ internals.utility = {
const method = internals.utility.formatMethod(event.method, settings);
const statusCode = internals.utility.formatStatusCode(event.statusCode, settings) || '';

// event, timestamp, id, instance, labels, method, path, query, responseTime,
// event, timestamp, id, instance, labels, method, path, query, responseTime, responseSentTime,
// statusCode, pid, httpVersion, source, remoteAddress, userAgent, referer, log
// method, pid, error
const output = `${event.instance}: ${method} ${event.path} ${query} ${statusCode} (${event.responseTime}ms)`;
const output = `${event.instance}: ${method} ${event.path} ${query} ${statusCode} (responseSentTime: ${event.responseSentTime}ms) (responseTime: ${event.responseTime}ms)`;

const response = {
timestamp: event.timestamp,
Expand Down
20 changes: 11 additions & 9 deletions test/index.js
Expand Up @@ -40,6 +40,7 @@ internals.ops = {
requests: {},
concurrents: {},
responseTimes: {},
responseSentTimes: {},
listener: {},
sockets: { http: {}, https: {} }
}
Expand All @@ -57,6 +58,7 @@ internals.response = {
name: 'adam'
},
responseTime: 150,
responseSentTime: 100,
statusCode: 200,
pid: 16014,
httpVersion: '1.1',
Expand Down Expand Up @@ -125,7 +127,7 @@ describe('GoodConsole', () => {
reader.once('end', () => {

expect(out.data).to.have.length(1);
expect(out.data[0]).to.be.equal('160318/013330.957, [response] http://localhost:61253: \u001b[1;33mpost\u001b[0m /data {"name":"adam"} \u001b[32m200\u001b[0m (150ms)\n');
expect(out.data[0]).to.be.equal('160318/013330.957, [response] http://localhost:61253: \u001b[1;33mpost\u001b[0m /data {"name":"adam"} \u001b[32m200\u001b[0m (responseSentTime: 100ms) (responseTime: 150ms)\n');
done();
});
});
Expand All @@ -146,7 +148,7 @@ describe('GoodConsole', () => {
reader.once('end', () => {

expect(out.data).to.have.length(1);
expect(out.data[0]).to.be.equal('160318/013330.957, [response] http://localhost:61253: \u001b[1;33mpost\u001b[0m /data \u001b[32m200\u001b[0m (150ms)\n');
expect(out.data[0]).to.be.equal('160318/013330.957, [response] http://localhost:61253: \u001b[1;33mpost\u001b[0m /data \u001b[32m200\u001b[0m (responseSentTime: 100ms) (responseTime: 150ms)\n');
done();
});
});
Expand All @@ -168,7 +170,7 @@ describe('GoodConsole', () => {
reader.once('end', () => {

expect(out.data).to.have.length(1);
expect(out.data[0]).to.be.equal('160318/013330.957, [response] http://localhost:61253: \u001b[1;33mpost\u001b[0m /data {"name":"adam"} (150ms)\n');
expect(out.data[0]).to.be.equal('160318/013330.957, [response] http://localhost:61253: \u001b[1;33mpost\u001b[0m /data {"name":"adam"} (responseSentTime: 100ms) (responseTime: 150ms)\n');
done();
});
});
Expand All @@ -187,7 +189,7 @@ describe('GoodConsole', () => {
reader.once('end', () => {

expect(out.data).to.have.length(1);
expect(out.data[0]).to.be.equal('160318/013330.957, [response] http://localhost:61253: post /data {"name":"adam"} 200 (150ms)\n');
expect(out.data[0]).to.be.equal('160318/013330.957, [response] http://localhost:61253: post /data {"name":"adam"} 200 (responseSentTime: 100ms) (responseTime: 150ms)\n');
done();
});
});
Expand All @@ -211,7 +213,7 @@ describe('GoodConsole', () => {
reader.once('end', () => {

expect(out.data).to.have.length(1);
expect(out.data[0]).to.be.equal(`${date}, [response] http://localhost:61253: \u001b[1;33mpost\u001b[0m /data {"name":"adam"} \u001b[32m200\u001b[0m (150ms)\n`);
expect(out.data[0]).to.be.equal(`${date}, [response] http://localhost:61253: \u001b[1;33mpost\u001b[0m /data {"name":"adam"} \u001b[32m200\u001b[0m (responseSentTime: 100ms) (responseTime: 150ms)\n`);
done();
});
});
Expand All @@ -233,7 +235,7 @@ describe('GoodConsole', () => {
reader.once('end', () => {

expect(out.data).to.have.length(1);
expect(out.data[0]).to.be.equal('160318/013330.957, [response] http://localhost:61253: \u001b[1;34mhead\u001b[0m /data {"name":"adam"} \u001b[32m200\u001b[0m (150ms)\n');
expect(out.data[0]).to.be.equal('160318/013330.957, [response] http://localhost:61253: \u001b[1;34mhead\u001b[0m /data {"name":"adam"} \u001b[32m200\u001b[0m (responseSentTime: 100ms) (responseTime: 150ms)\n');
done();
});
});
Expand All @@ -255,7 +257,7 @@ describe('GoodConsole', () => {
reader.once('end', () => {

expect(out.data).to.have.length(1);
expect(out.data[0]).to.be.equal('160318/013330.957, [response] http://localhost:61253: \u001b[1;33mpost\u001b[0m /data {"name":"adam"} \u001b[31m599\u001b[0m (150ms)\n');
expect(out.data[0]).to.be.equal('160318/013330.957, [response] http://localhost:61253: \u001b[1;33mpost\u001b[0m /data {"name":"adam"} \u001b[31m599\u001b[0m (responseSentTime: 100ms) (responseTime: 150ms)\n');
done();
});
});
Expand All @@ -277,7 +279,7 @@ describe('GoodConsole', () => {
reader.once('end', () => {

expect(out.data).to.have.length(1);
expect(out.data[0]).to.be.equal('160318/013330.957, [response] http://localhost:61253: \u001b[1;33mpost\u001b[0m /data {"name":"adam"} \u001b[33m418\u001b[0m (150ms)\n');
expect(out.data[0]).to.be.equal('160318/013330.957, [response] http://localhost:61253: \u001b[1;33mpost\u001b[0m /data {"name":"adam"} \u001b[33m418\u001b[0m (responseSentTime: 100ms) (responseTime: 150ms)\n');
done();
});
});
Expand All @@ -299,7 +301,7 @@ describe('GoodConsole', () => {
reader.once('end', () => {

expect(out.data).to.have.length(1);
expect(out.data[0]).to.be.equal('160318/013330.957, [response] http://localhost:61253: \u001b[1;33mpost\u001b[0m /data {"name":"adam"} \u001b[36m304\u001b[0m (150ms)\n');
expect(out.data[0]).to.be.equal('160318/013330.957, [response] http://localhost:61253: \u001b[1;33mpost\u001b[0m /data {"name":"adam"} \u001b[36m304\u001b[0m (responseSentTime: 100ms) (responseTime: 150ms)\n');
done();
});
});
Expand Down

0 comments on commit eb54cd1

Please sign in to comment.