diff --git a/packages/logger/CHANGELOG.md b/packages/logger/CHANGELOG.md new file mode 100644 index 000000000..5addc24d9 --- /dev/null +++ b/packages/logger/CHANGELOG.md @@ -0,0 +1,13 @@ +# @adguard/logger Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [1.0.1] - 2024-05-24 + +### Fixed +- Bug with logging `null` values [AdGuardVPNExtension#176] + +[AdGuardVPNExtension#176]: https://github.com/AdguardTeam/AdGuardVPNExtension/issues/176 diff --git a/packages/logger/src/Logger.ts b/packages/logger/src/Logger.ts index 1b286752a..6501dc549 100644 --- a/packages/logger/src/Logger.ts +++ b/packages/logger/src/Logger.ts @@ -189,11 +189,11 @@ export class Logger { return Logger.errorToString(value); } - if (typeof value.message === 'string') { + if (value && typeof value.message === 'string') { return value.message; } - if (typeof value === 'object') { + if (typeof value === 'object' && value !== null) { return JSON.stringify(value); } diff --git a/packages/logger/tests/logger.test.ts b/packages/logger/tests/logger.test.ts index 85f6e39ce..18db80d8a 100644 --- a/packages/logger/tests/logger.test.ts +++ b/packages/logger/tests/logger.test.ts @@ -12,6 +12,20 @@ describe('works', () => { jest.clearAllMocks(); }); + describe('logs any message', () => { + it('logs null', () => { + const logger = new Logger(writer); + logger.info('test', null); + expect(writer.info).toHaveBeenCalledWith(expect.any(String), 'test', 'null'); + }); + + it('logs undefined', () => { + const logger = new Logger(writer); + logger.info('test', undefined); + expect(writer.info).toHaveBeenCalledWith(expect.any(String), 'test', 'undefined'); + }); + }); + describe('calls expected method of writer', () => { it('info calls info', () => { const logger = new Logger(writer);