Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Logger with log levels #1672

Merged
merged 4 commits into from
Oct 20, 2023
Merged

feat: Logger with log levels #1672

merged 4 commits into from
Oct 20, 2023

Conversation

danisharora099
Copy link
Collaborator

Problem

We currently use the native debug for all logging purposes.
This is tricky -- while we want to add as many logs as possible to ensure smooth debugging, information travel, etc, we also don't want to limit readability & flood logs.

Solution

Allow usage of segregating logs by level: log.info(), log.warn() -- this would enable library consumers to choose the log level they want to watch, help us add as many logs as possible based on the level.

Notes

  • Upon reviewing our problem statement, and existing libraries, best to make use of the native debug and console packages by creating a wrapper to allow of log levels and prefixes to keep things lightweight without adding dependency on a new package
  • We now disable usage of the debug package across the codebase directly, and only allow usage through the Logger class
  • Resolves feat: enable logs based on log levels #1659

@danisharora099 danisharora099 requested a review from a team as a code owner October 18, 2023 12:57
@github-actions
Copy link

github-actions bot commented Oct 18, 2023

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
Waku core 83.8 KB (+0.3% 🔺) 1.7 s (+0.3% 🔺) 4.5 s (+98.75% 🔺) 6.2 s
Waku Simple Light Node 264.06 KB (+0.08% 🔺) 5.3 s (+0.08% 🔺) 5.7 s (+13.53% 🔺) 11 s
ECIES encryption 79.48 KB (+0.22% 🔺) 1.6 s (+0.22% 🔺) 3.7 s (+9.19% 🔺) 5.3 s
Symmetric encryption 79.49 KB (+0.22% 🔺) 1.6 s (+0.22% 🔺) 4.3 s (+108.84% 🔺) 5.9 s
DNS discovery 111.24 KB (+0.17% 🔺) 2.3 s (+0.17% 🔺) 3.7 s (-9.95% 🔽) 5.9 s
Privacy preserving protocols 131.8 KB (+0.18% 🔺) 2.7 s (+0.18% 🔺) 4.3 s (+9.04% 🔺) 6.9 s
Light protocols 81.5 KB (+0.25% 🔺) 1.7 s (+0.25% 🔺) 2.5 s (-13.13% 🔽) 4.2 s
History retrieval protocols 80.55 KB (+0.23% 🔺) 1.7 s (+0.23% 🔺) 2.1 s (-5.92% 🔽) 3.7 s
Deterministic Message Hashing 5.65 KB (0%) 113 ms (0%) 497 ms (+44.62% 🔺) 610 ms

this._warn = debug(Logger.createDebugNamespace("WARN", prefix));
this._error = debug(Logger.createDebugNamespace("ERROR", prefix));

this._info.log = console.info.bind(console);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing is better than good old console.* 😄

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this compatible with libp2p logging approach?

Copy link
Collaborator Author

@danisharora099 danisharora099 Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it isn't -- #1677 re-enables that functionality @fryorcraken

@danisharora099 danisharora099 merged commit 0f7d63e into master Oct 20, 2023
@danisharora099 danisharora099 deleted the feat/loglevel branch October 20, 2023 11:06
danisharora099 added a commit that referenced this pull request Oct 20, 2023
* setup a custom Logger with log level support

* refactor codebase for to use new Logger with log levels

* disallow usage of `debug` directly / only allow usage in/through custom Logger

* remove `debug` from logger
@fbarbu15 fbarbu15 mentioned this pull request Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: enable logs based on log levels
3 participants