Skip to content

Add log stream and callback to constructor#222

Merged
CharlVS merged 2 commits intodevfrom
cursor/add-log-stream-and-callback-to-constructor-cc4d
Sep 22, 2025
Merged

Add log stream and callback to constructor#222
CharlVS merged 2 commits intodevfrom
cursor/add-log-stream-and-callback-to-constructor-cc4d

Conversation

@CharlVS
Copy link
Copy Markdown
Collaborator

@CharlVS CharlVS commented Sep 15, 2025

Expose KomodoDefiSdk log stream and add an optional onLog callback to its constructors to allow external log handling.


Open in Cursor Open in Web

This commit introduces the ability to pass an external logger function to the KomodoDefiSdk, allowing for custom logging of framework messages.

Co-authored-by: charl <charl@vanstaden.info>
@cursor
Copy link
Copy Markdown

cursor bot commented Sep 15, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Sep 15, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cursor/add-log-stream-and-callback-to-constructor-cc4d

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

cursor[bot]

This comment was marked as outdated.

@CharlVS CharlVS marked this pull request as ready for review September 15, 2025 13:51
Copilot AI review requested due to automatic review settings September 15, 2025 13:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds logging capabilities to the KomodoDefiSdk by exposing its log stream and adding an optional onLog callback parameter to both constructor methods.

  • Adds an optional onLog callback parameter to both SDK constructors for external log handling
  • Exposes a public logStream getter that provides access to framework logs
  • Manages log subscription lifecycle by properly disposing of the subscription when the SDK is disposed

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/komodo_defi_sdk/lib/src/komodo_defi_sdk.dart Adds onLog callback parameter to constructors, implements log stream subscription management, and exposes public logStream getter
packages/komodo_defi_sdk/lib/src/bootstrap.dart Updates bootstrap function to accept and use external logger callback for framework creation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +156 to +158
if (_kdfFramework != null && _onLog != null) {
_logSubscription = _kdfFramework!.logStream.listen(_onLog!);
}
Copy link

Copilot AI Sep 15, 2025

Choose a reason for hiding this comment

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

This creates a log subscription only when _kdfFramework is provided in the constructor, but when using the default constructor, the framework is created later during initialization. This means the log subscription will never be established for the default constructor case.

Copilot uses AI. Check for mistakes.
Comment on lines +291 to +293
Stream<String> get logStream => _assertSdkInitialized(
_container<KomodoDefiFramework>().logStream,
);
Copy link

Copilot AI Sep 15, 2025

Choose a reason for hiding this comment

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

The logStream getter accesses the framework through the container, but there's no guarantee that the log subscription is properly established for all initialization paths. Consider adding logic in the initialization process to ensure the log subscription is created when needed.

Copilot uses AI. Check for mistakes.
@CharlVS
Copy link
Copy Markdown
Collaborator Author

CharlVS commented Sep 16, 2025

@cursor fix the PR comments

@cursor
Copy link
Copy Markdown

cursor bot commented Sep 16, 2025

I refactored the logging mechanism within KomodoDefiSdk to centralize and ensure proper management of log stream subscriptions. This prevents duplicate subscriptions during initialization and guarantees consistent cancellation during disposal, improving robustness.

  • I modified the KomodoDefiSdk.init() method in packages/komodo_defi_sdk/lib/src/komodo_defi_sdk.dart to no longer pass externalLogger: _onLog directly to the KomodoDefiFramework constructor. Instead, I explicitly subscribe _onLog to framework.logStream after the framework is instantiated, ensuring the SDK manages its own log subscription.
  • I relocated the cancellation of _logSubscription within KomodoDefiSdk.dispose(). It now occurs at the very beginning of the method, ensuring the log stream subscription is always cancelled, even if the SDK was not fully initialized.

Open in Cursor Open in Web

Learn more about Cursor Agents

Co-authored-by: charl <charl@vanstaden.info>
@CharlVS CharlVS merged commit ab65b10 into dev Sep 22, 2025
4 of 8 checks passed
@CharlVS CharlVS deleted the cursor/add-log-stream-and-callback-to-constructor-cc4d branch September 22, 2025 10:57
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.

3 participants