From 3438c528efed21285ab31c4dde57e8b6031625f2 Mon Sep 17 00:00:00 2001 From: Slava Leleka Date: Mon, 23 Sep 2024 15:12:56 +0300 Subject: [PATCH] bind logger methods to avoid losing context. AG-35957 Squashed commit of the following: commit a2ca25e5b9a8b380a9314fb496c9c0f81fb2fe78 Author: Slava Leleka Date: Fri Sep 20 22:35:16 2024 +0300 bump version, update changelog commit f959c30860fec27946b1d7f526820a4103ffd01c Author: Slava Leleka Date: Fri Sep 20 22:26:51 2024 +0300 update comments commit 642dc4937e5ada55cba51d72d69660e2da43e584 Author: Slava Leleka Date: Fri Sep 20 22:26:29 2024 +0300 bind logger methods to avoid losing context commit 434560233f46648f0ec9348f2be166169dfc2763 Author: Slava Leleka Date: Fri Sep 20 22:25:29 2024 +0300 fix spaces --- bamboo-specs/logger-build.yaml | 2 +- packages/logger/CHANGELOG.md | 13 ++++++++++++- packages/logger/package.json | 2 +- packages/logger/src/Logger.ts | 11 ++++++++++- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/bamboo-specs/logger-build.yaml b/bamboo-specs/logger-build.yaml index 78e6664b7..44f412099 100644 --- a/bamboo-specs/logger-build.yaml +++ b/bamboo-specs/logger-build.yaml @@ -74,7 +74,7 @@ Build: echo "Size before cleanup:" && du -h | tail -n 1 pnpm clean - + echo "Size after cleanup:" && du -h | tail -n 1 # Store the logger package tarball as an artifact artifacts: diff --git a/packages/logger/CHANGELOG.md b/packages/logger/CHANGELOG.md index 5addc24d9..02deaa391 100644 --- a/packages/logger/CHANGELOG.md +++ b/packages/logger/CHANGELOG.md @@ -5,9 +5,20 @@ 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.2] - 2024-09-23 + +### Fixed + +- Logging methods binding to the logger instance to avoid losing the context. + +[1.0.2]: https://github.com/AdguardTeam/tsurlfilter/releases/tag/logger-v1.0.2 + + ## [1.0.1] - 2024-05-24 ### Fixed -- Bug with logging `null` values [AdGuardVPNExtension#176] +- Bug with logging `null` values [AdGuardVPNExtension#176]. + +[1.0.1]: https://github.com/AdguardTeam/tsurlfilter/releases/tag/logger-v1.0.1 [AdGuardVPNExtension#176]: https://github.com/AdguardTeam/AdGuardVPNExtension/issues/176 diff --git a/packages/logger/package.json b/packages/logger/package.json index ed13764c6..3ef1258ea 100644 --- a/packages/logger/package.json +++ b/packages/logger/package.json @@ -1,6 +1,6 @@ { "name": "@adguard/logger", - "version": "1.0.1", + "version": "1.0.2", "scripts": { "prebuild": "rimraf dist", "build": "pnpm prebuild && rollup -c rollup.config.ts --configPlugin typescript && pnpm build:types && pnpm build:txt", diff --git a/packages/logger/src/Logger.ts b/packages/logger/src/Logger.ts index 6501dc549..153ecb255 100644 --- a/packages/logger/src/Logger.ts +++ b/packages/logger/src/Logger.ts @@ -73,7 +73,7 @@ export interface Writer { * @param args */ error: (...args: any[]) => void; - // We do not print error, since in the extensions warn is counted as error. + // We do not use 'warn' channel, since in the extensions warn is counted as error. // warn: (...args: any[]) => void; } @@ -91,10 +91,17 @@ export class Logger { */ constructor(writer: Writer = console) { this.writer = writer; + + // bing the logging methods to avoid losing context + this.debug = this.debug.bind(this); + this.info = this.info.bind(this); + this.warn = this.warn.bind(this); + this.error = this.error.bind(this); } /** * Print debug messages. Usually used for technical information. + * Will be printed in 'log' channel. * * @param args Printed arguments. */ @@ -113,6 +120,8 @@ export class Logger { /** * Print warn messages. + * NOTE: We do not use 'warn' channel, since in the extensions warn is + * counted as error. Instead of this we use 'info' channel. * * @param args Printed arguments. */