Skip to content

Commit

Permalink
AG-32945 add possibility to log null
Browse files Browse the repository at this point in the history
Merge in ADGUARD-FILTERS/tsurlfilter from fix/AG-32945 to master

Squashed commit of the following:

commit 68f8481
Author: Maxim Topciu <[email protected]>
Date:   Fri May 24 13:22:09 2024 +0300

    AG-32945 remove comments

commit 98e0d5a
Author: Maxim Topciu <[email protected]>
Date:   Fri May 24 12:03:26 2024 +0300

    AG-32945 add changelog

commit 56663c5
Author: Maxim Topciu <[email protected]>
Date:   Fri May 24 11:55:02 2024 +0300

    AG-32945 add possibility to log null
  • Loading branch information
maximtop committed May 24, 2024
1 parent 79cc91e commit b23412c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
13 changes: 13 additions & 0 deletions packages/logger/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions packages/logger/src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
14 changes: 14 additions & 0 deletions packages/logger/tests/logger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b23412c

Please sign in to comment.