Skip to content

Commit

Permalink
bind logger methods to avoid losing context. AG-35957
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit a2ca25e
Author: Slava Leleka <[email protected]>
Date:   Fri Sep 20 22:35:16 2024 +0300

    bump version, update changelog

commit f959c30
Author: Slava Leleka <[email protected]>
Date:   Fri Sep 20 22:26:51 2024 +0300

    update comments

commit 642dc49
Author: Slava Leleka <[email protected]>
Date:   Fri Sep 20 22:26:29 2024 +0300

    bind logger methods to avoid losing context

commit 4345602
Author: Slava Leleka <[email protected]>
Date:   Fri Sep 20 22:25:29 2024 +0300

    fix spaces
  • Loading branch information
slavaleleka committed Sep 23, 2024
1 parent 1fcf0fa commit 3438c52
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bamboo-specs/logger-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
13 changes: 12 additions & 1 deletion packages/logger/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion packages/logger/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
11 changes: 10 additions & 1 deletion packages/logger/src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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.
*/
Expand All @@ -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.
*/
Expand Down

0 comments on commit 3438c52

Please sign in to comment.