Skip to content

Commit

Permalink
AG-36533 Added collapsed tracing
Browse files Browse the repository at this point in the history
Merge in ADGUARD-FILTERS/tsurlfilter from feature/AG-36533 to master

Squashed commit of the following:

commit c55c340
Merge: bcb663b 7383903
Author: Kurbanali Ruslan <[email protected]>
Date:   Thu Oct 10 19:49:33 2024 +0500

    Merge branch 'master' into feature/AG-36533

commit bcb663b
Author: Kurbanali Ruslan <[email protected]>
Date:   Thu Oct 10 19:47:15 2024 +0500

    fixed changelog

commit a3d5dd3
Author: Kurbanali Ruslan <[email protected]>
Date:   Thu Oct 10 19:36:03 2024 +0500

    added collapsed tracing
  • Loading branch information
kurrx committed Oct 10, 2024
1 parent 7383903 commit 0384d8d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
8 changes: 8 additions & 0 deletions packages/logger/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ 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.1.1] - 2024-10-10

### Changed

- Tracing in console is collapsed by default.

[1.1.1]: https://github.com/AdguardTeam/tsurlfilter/releases/tag/logger-v1.1.1

## [1.1.0] - 2024-10-08

### Added
Expand Down
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.1.0",
"version": "1.1.1",
"scripts": {
"prebuild": "rimraf dist",
"build": "pnpm prebuild && rollup -c rollup.config.ts --configPlugin typescript && pnpm build:types && pnpm build:txt",
Expand Down
34 changes: 28 additions & 6 deletions packages/logger/src/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ export interface Writer {
*/
trace?: WriterMethod;

/**
* Group collapsed method.
* @param args
*/
groupCollapsed?: WriterMethod;

/**
* Group end method.
* @param args
*/
groupEnd?: WriterMethod;

// We do not use 'warn' channel, since in the extensions warn is counted as error.
// warn: WriterMethod;
}
Expand Down Expand Up @@ -237,14 +249,24 @@ export class Logger {
* 3. Writer has `trace` method.
*/
if (
method !== LogMethod.Error
&& this.currentLevelValue >= levelMapStringToNum[LogLevel.Trace]
&& 'trace' in this.writer
&& typeof this.writer.trace === 'function'
method === LogMethod.Error
|| this.currentLevelValue < levelMapStringToNum[LogLevel.Trace]
|| !this.writer.trace
) {
this.writer.trace(formattedTime, ...formattedArgs);
} else {
// Print with regular method
this.writer[method](formattedTime, ...formattedArgs);
return;
}

if (!this.writer.groupCollapsed || !this.writer.groupEnd) {
// Print expanded trace
this.writer.trace(formattedTime, ...formattedArgs);
return;
}

// Print collapsed trace
this.writer.groupCollapsed(formattedTime, ...formattedArgs);
this.writer.trace();
this.writer.groupEnd();
}
}

0 comments on commit 0384d8d

Please sign in to comment.