Skip to content

Commit

Permalink
Merge branch 'development/8.1' into dependabot/npm_and_yarn/semver-5.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
francoisferrand committed May 13, 2024
2 parents 5eb29b5 + 10af7a1 commit 4a5237f
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 66 deletions.
15 changes: 5 additions & 10 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@ name: Tests

on:
push:
branches:
- 'feature/**'
- 'documentation/**'
- 'improvement/**'
- 'bugfix/**'
- 'w/**'
- 'q/**'
- 'hotfix/**'
branches-ignore:
- development/**
- q/*/**

jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: Checkokut
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Install deps
run: sudo apt-get update -q
- uses: actions/setup-node@v2
- uses: actions/setup-node@v4
with:
node-version: '16'
- name: Install Yarn
Expand Down
15 changes: 6 additions & 9 deletions lib/RequestLogger.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

// eslint-disable-line strict

const assert = require('assert');

const LogLevel = require('./LogLevel.js');
const Utils = require('./Utils.js');

Expand All @@ -23,9 +21,6 @@ class EndLogger {
}

augmentedLog(level, msg, data) {
assert.strictEqual(this.logger.elapsedTime, null, 'The logger\'s'
+ 'end() wrapper should not be called more than'
+ ' once.');
// We can alter current instance, as it won't be usable after this
// call.
this.fields = objectCopy(this.fields, data || {});
Expand Down Expand Up @@ -370,8 +365,6 @@ class RequestLogger {
if (msg === undefined && data === undefined) {
return this.endLogger;
}
assert.strictEqual(this.elapsedTime, null, 'The "end()" logging method '
+ 'should not be called more than once.');
return this.log(this.endLevel, msg, data, true);
}

Expand All @@ -388,8 +381,6 @@ class RequestLogger {
* @returns {undefined}
*/
errorEnd(msg, data) {
assert.strictEqual(this.elapsedTime, null, 'The "end()" logging method '
+ 'should not be called more than once.');
return this.log('error', msg, data, true);
}

Expand Down Expand Up @@ -449,6 +440,12 @@ class RequestLogger {
// eslint-disable-next-line camelcase
fields.req_id = serializeUids(this.uids);
if (endFlag) {
if (this.elapsedTime !== null) {
// reset elapsedTime to avoid an infinite recursion
// while logging the error
this.elapsedTime = null;
this.error('RequestLogger.end() has been called more than once');
}
this.elapsedTime = process.hrtime(this.startTime);
// eslint-disable-next-line camelcase
fields.elapsed_ms = this.elapsedTime[0] * 1000
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"engines": {
"node": ">=10"
},
"version": "8.1.3",
"version": "8.1.4",
"description": "An efficient raw JSON logging library aimed at micro-services architectures.",
"main": "index.js",
"scripts": {
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/RequestLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,21 @@ describe('RequestLogger', () => {
assert.strictEqual(dummyLogger.ops[0][1][0].endValue, 42);
done();
});

it('should log an error in addition to request logs when end() called more than once',
done => {
const dummyLogger = new DummyLogger();
const reqLogger = new RequestLogger(dummyLogger, 'trace', 'fatal');
reqLogger.end().info('after first call to end()');
reqLogger.end().debug('after second call to end()');
assert.strictEqual(dummyLogger.ops.length, 3);
assert.strictEqual(dummyLogger.ops[0][0], 'info');
assert.strictEqual(dummyLogger.ops[0][1][1], 'after first call to end()');
assert.strictEqual(dummyLogger.ops[1][0], 'error');
assert.strictEqual(dummyLogger.ops[2][0], 'debug');
assert.strictEqual(dummyLogger.ops[2][1][1], 'after second call to end()');
done();
});
});

describe('Log History dumped when logging floor level reached', () => {
Expand Down
Loading

0 comments on commit 4a5237f

Please sign in to comment.