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): implement configurable logging system #264

Merged
merged 7 commits into from
Sep 18, 2024

Conversation

drichar
Copy link
Collaborator

@drichar drichar commented Sep 17, 2024

Description

This PR introduces a centralized logging system to improve debugging and error tracking across the entire library. It replaces direct console logging with a new Logger class that provides consistent, configurable logging functionality. The PR also adds new configuration options to WalletManager for fine-grained control over logging behavior.

Details

  • Created a new Logger class with support for different log levels (DEBUG, INFO, WARN, ERROR)
  • Implemented a singleton pattern for the Logger to ensure consistent usage across the application
  • Added support for scoped logging to provide context for log messages
  • Updated all wallet implementations to use the new logging system
  • Replaced console.log, console.warn, and console.error calls with appropriate logger methods
  • Added unit tests for the Logger class to ensure proper functionality
  • Updated existing tests to use mocked logger instances
  • Exposed new configuration options in WalletManager:
    • logLevel (enum): Allows precise control over the log level
    • debug (boolean): Convenience option to easily set log level to DEBUG
  • Improved error handling and debugging information in various wallet implementations

These will all be replaced with the debugging logger that will be introduced in this branch.
- Replaced `console.info`, `console.warn`, and `console.error` calls with appropriate logger methods (`this.logger.info`, `this.logger.warn`, `this.logger.error`, `this.logger.debug`)
- Wrapped `signTransactions` method logic in a try/catch block to handle and log errors consistently
- Ensured that all wallet clients leverage the scoped logger created in the `BaseWallet` class
- Added more logging statements to provide better visibility into the wallets' operations
- Add detailed logging to `signTransactions` methods across wallet clients.
- Include debug logs for transaction processing steps and results.
This commit refactors the createAlgodClient method in the WalletManager class to improve its functionality and logging. The main changes are:

- Update method signature to accept `networkId` instead of `config`
- Move network config retrieval inside the method
- Adjust logging to use the passed `networkId` parameter

These changes should resolve issues related to accessing the active network property on initialization and improve the overall structure of the method.
This commit updates the wallet test files to use the new `Logger` system instead of `console` logging. The main changes include:

- Update mock setup for logger in all wallet test files
- Replace `console.warn` and `console.error` expectations with `logger.warn` and `logger.error` in relevant tests
- Adjust test assertions to check for `logger` calls instead of `console` calls
- Remove unused `console` mocks from test files
- Replace `console.warn` calls with `logger.warn` in store functions
- Update tests to mock the `logger` to suppress output during test runs
- Create new test file for `Logger` class
- Implement tests for singleton instance, log levels, and scoped logging
- Add `setIsClient` method to Logger for testing purposes
- Ensure tests cover all logging scenarios and respect log levels
@drichar drichar merged commit 53057b5 into main Sep 18, 2024
1 check passed
@drichar drichar deleted the feat/config-options-debug branch September 18, 2024 01:38
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.

1 participant