-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logger): implement configurable logging system (#264)
* refactor: replace every console.log with console.info These will all be replaced with the debugging logger that will be introduced in this branch. * refactor(*): update logging system for wallet clients - 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 * refactor(wallets): enhance signTransactions logging - Add detailed logging to `signTransactions` methods across wallet clients. - Include debug logs for transaction processing steps and results. * refactor(WalletManager): update createAlgodClient method 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. * test(wallets): update wallet tests to use mocked Logger 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 * refactor(store): replace console with logger in store functions - Replace `console.warn` calls with `logger.warn` in store functions - Update tests to mock the `logger` to suppress output during test runs * test(logger): add unit tests for Logger class - 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
- Loading branch information
Showing
31 changed files
with
1,084 additions
and
457 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import { Logger, LogLevel } from 'src/logger' | ||
|
||
describe('Logger', () => { | ||
let logger: Logger | ||
let consoleWarnSpy: ReturnType<typeof vi.spyOn> | ||
let consoleErrorSpy: ReturnType<typeof vi.spyOn> | ||
let consoleInfoSpy: ReturnType<typeof vi.spyOn> | ||
|
||
beforeEach(() => { | ||
// Reset singleton instance | ||
Logger['instance'] = null | ||
logger = Logger.getInstance() | ||
|
||
// Set isClient to true for testing | ||
logger.setIsClient(true) | ||
|
||
// Mock console methods | ||
consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {}) | ||
consoleErrorSpy = vi.spyOn(console, 'error').mockImplementation(() => {}) | ||
consoleInfoSpy = vi.spyOn(console, 'info').mockImplementation(() => {}) | ||
|
||
// Set log level to DEBUG | ||
Logger.setLevel(LogLevel.DEBUG) | ||
}) | ||
|
||
afterEach(() => { | ||
vi.restoreAllMocks() | ||
}) | ||
|
||
it('should return the same instance', () => { | ||
const logger1 = Logger.getInstance() | ||
const logger2 = Logger.getInstance() | ||
expect(logger1).toBe(logger2) | ||
}) | ||
|
||
it('should log at all levels when set to DEBUG', () => { | ||
logger.debug('Test debug') | ||
logger.info('Test info') | ||
logger.warn('Test warn') | ||
logger.error('Test error') | ||
|
||
expect(consoleInfoSpy).toHaveBeenCalledWith('Test debug') | ||
expect(consoleInfoSpy).toHaveBeenCalledWith('Test info') | ||
expect(consoleWarnSpy).toHaveBeenCalledWith('Test warn') | ||
expect(consoleErrorSpy).toHaveBeenCalledWith('Test error') | ||
}) | ||
|
||
it('should respect log level changes', () => { | ||
Logger.setLevel(LogLevel.WARN) | ||
|
||
logger.debug('Test debug') | ||
logger.info('Test info') | ||
logger.warn('Test warn') | ||
logger.error('Test error') | ||
|
||
expect(consoleInfoSpy).not.toHaveBeenCalled() | ||
expect(consoleWarnSpy).toHaveBeenCalledWith('Test warn') | ||
expect(consoleErrorSpy).toHaveBeenCalledWith('Test error') | ||
}) | ||
|
||
it('should only log errors when set to ERROR level', () => { | ||
Logger.setLevel(LogLevel.ERROR) | ||
|
||
logger.debug('Test debug') | ||
logger.info('Test info') | ||
logger.warn('Test warn') | ||
logger.error('Test error') | ||
|
||
expect(consoleInfoSpy).not.toHaveBeenCalled() | ||
expect(consoleWarnSpy).not.toHaveBeenCalled() | ||
expect(consoleErrorSpy).toHaveBeenCalledWith('Test error') | ||
}) | ||
|
||
it('should log with scope when using scoped logger', () => { | ||
const scopedLogger = logger.createScopedLogger('MyScope') | ||
|
||
scopedLogger.debug('Scoped debug') | ||
scopedLogger.info('Scoped info') | ||
scopedLogger.warn('Scoped warn') | ||
scopedLogger.error('Scoped error') | ||
|
||
expect(consoleInfoSpy).toHaveBeenCalledWith('[MyScope] Scoped debug') | ||
expect(consoleInfoSpy).toHaveBeenCalledWith('[MyScope] Scoped info') | ||
expect(consoleWarnSpy).toHaveBeenCalledWith('[MyScope] Scoped warn') | ||
expect(consoleErrorSpy).toHaveBeenCalledWith('[MyScope] Scoped error') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.