Skip to content

Commit

Permalink
Add some namespace hierarchy filter tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoz committed Jun 3, 2024
1 parent 0abcd94 commit b6fef7e
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions test/logger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,37 @@ describe('Logger', () => {
expect(logSpy).toHaveBeenCalledTimes(3);
expect(consoleWriteSpy).toHaveBeenCalledTimes(3);
});
it('Logs with namespaced levels hierarchy', () => {
logger.setNamespacedLevels({'zh:zstack': 'debug', 'zh:zstack:unpi:writer': 'error'})
logger.setLevel('warning');

const logSpy = jest.spyOn(logger.winston, 'log');

consoleWriteSpy.mockClear();
logger.debug(`--- parseNext [] debug picked from hierarchy`, 'zh:zstack:unpi:parser');
expect(logSpy).toHaveBeenCalledTimes(1);
expect(consoleWriteSpy).toHaveBeenCalledTimes(1);
logger.warning(`--> frame [36,15] warning explicitely supressed`, 'zh:zstack:unpi:writer');
expect(logSpy).toHaveBeenCalledTimes(1);
expect(consoleWriteSpy).toHaveBeenCalledTimes(1);
logger.warning(`Another supressed warning message in a sub namespace`, 'zh:zstack:unpi:writer:sub:ns');
expect(logSpy).toHaveBeenCalledTimes(1);
expect(consoleWriteSpy).toHaveBeenCalledTimes(1);
logger.error(`but error should go through`, 'zh:zstack:unpi:writer:another:sub:ns');
expect(logSpy).toHaveBeenCalledTimes(2);
expect(consoleWriteSpy).toHaveBeenCalledTimes(2);
logger.warning(`unconfigured namespace warning`, 'z2m:mqtt');
expect(logSpy).toHaveBeenCalledTimes(3);
expect(consoleWriteSpy).toHaveBeenCalledTimes(3);
logger.info(`cached unconfigured namespace info should be supressed`, 'z2m:mqtt');
expect(logSpy).toHaveBeenCalledTimes(3);
expect(consoleWriteSpy).toHaveBeenCalledTimes(3);

logger.setLevel('info');
logger.info(`unconfigured namespace info should pass after default level change`, 'z2m:mqtt');
expect(logSpy).toHaveBeenCalledTimes(4);
expect(consoleWriteSpy).toHaveBeenCalledTimes(4);


});
});

0 comments on commit b6fef7e

Please sign in to comment.