Skip to content

Commit 958c076

Browse files
fix: remove console.log from default arg
1 parent cf60ae4 commit 958c076

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

__tests__/drivers/console-log-test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,12 @@ describe('drivers/console-log', () => {
6464

6565
expect(consoleInfoStub).calledOnceWith(LOG_ERROR_COLOR, sinon.match(message));
6666
});
67+
68+
it('should log with custom output logger', () => {
69+
const custom = sinon.stub();
70+
71+
ConsoleLog(custom)(getMessage, LogType.ERROR, 1);
72+
73+
expect(custom).calledOnceWith(LOG_ERROR_COLOR, sinon.match(message));
74+
});
6775
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lomray/microservice-nodejs-lib",
3-
"version": "2.4.2",
3+
"version": "2.4.3",
44
"description": "Package for create microservice architecture based on NodeJS & inverted json.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

src/drivers/console-log.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const reqIds = new Map();
1313
* @constructor
1414
*/
1515
const ConsoleLog: ConsoleInfoType =
16-
(log = console.info) =>
16+
(log) =>
1717
(getMessage, type = LogType.INFO, id = 0) => {
1818
let color = '';
1919
let reqTime = '';
@@ -58,7 +58,11 @@ const ConsoleLog: ConsoleInfoType =
5858
}
5959
}
6060

61-
log(color, `${getMessage()} ${reqTime}`);
61+
if (log === undefined) {
62+
console.info(color, `${getMessage()} ${reqTime}`);
63+
} else if (log) {
64+
log(color, `${getMessage()} ${reqTime}`);
65+
}
6266
};
6367

6468
export default ConsoleLog;

0 commit comments

Comments
 (0)