Skip to content

feat: add async support to logger methods and update README#24

Merged
tianyingchun merged 2 commits intohyperse-io:mainfrom
tclxshunquan-wang:feat/support_promise
Aug 6, 2025
Merged

feat: add async support to logger methods and update README#24
tianyingchun merged 2 commits intohyperse-io:mainfrom
tclxshunquan-wang:feat/support_promise

Conversation

@tclxshunquan-wang
Copy link
Contributor

@tclxshunquan-wang tclxshunquan-wang commented Aug 6, 2025

Summary by CodeRabbit

  • New Features

    • Added built-in asynchronous support for logger methods, allowing logging operations to be awaited.
  • Documentation

    • Updated documentation to highlight new async support for logging operations.
  • Bug Fixes

    • Corrected a typo in the logger interface implementation.
  • Tests

    • Updated all logger-related tests to await logging calls directly, ensuring reliable completion of asynchronous operations.
    • Removed unnecessary sleep utilities and related imports from test files.
  • Chores

    • Cleaned up and removed unused sleep utility functions from test utilities.

@coderabbitai
Copy link

coderabbitai bot commented Aug 6, 2025

Walkthrough

This update introduces asynchronous support to logger methods across the @hyperse/logger, @hyperse/logger-plugin-console, and @hyperse/logger-plugin-stdout packages. Logger method signatures are updated to return promises, and all internal and test code is refactored to use await on logger calls. Documentation and test utilities are updated accordingly.

Changes

Cohort / File(s) Change Summary
Logger Core & Types
packages/logger/src/core/logger.ts, packages/logger/src/types/type-logger.ts
Logger method signatures updated from synchronous (void) to asynchronous (Promise<void>); implementation updated to use async/await; interface typo corrected.
Test Suites Refactor
packages/logger/tests/logger.spec.ts, packages/logger/tests/error.spec.ts, packages/logger/tests/ctx.spec.ts, packages/logger-plugin-console/tests/console-plugin.spec.ts, packages/logger-plugin-stdout/tests/stdout-plugin.spec.ts
All logger method calls in tests are now awaited directly, removing the need for artificial sleep delays; imports of sleep removed.
Test Utility Cleanup
packages/logger/tests/test-utils.ts, packages/logger-plugin-console/tests/test-utils.ts, packages/logger-plugin-stdout/tests/test-utils.ts
The sleep utility function is deleted from all test utility files as it is no longer required.
Documentation
README.md
Added an entry under "Features" highlighting new async support.
Changeset Metadata
.changeset/long-meals-cross.md
Documents the asynchronous logger support and marks the update as a patch.

Sequence Diagram(s)

sequenceDiagram
    participant Test
    participant Logger
    participant Pipeline

    Test->>+Logger: await logger.info(message)
    Logger->>+Pipeline: await pipeline.execute(message)
    Pipeline-->>-Logger: (resolves)
    Logger-->>-Test: (resolves Promise)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Poem

Async logs now hop and leap,
Promises kept, no need for sleep.
Test bunnies wait, their paws at rest,
Awaiting logs that pass the test.
With every hop, the code grows bright—
Async logging done just right!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ea39706 and 4f17fef.

📒 Files selected for processing (12)
  • .changeset/long-meals-cross.md (1 hunks)
  • README.md (1 hunks)
  • packages/logger-plugin-console/tests/console-plugin.spec.ts (6 hunks)
  • packages/logger-plugin-console/tests/test-utils.ts (0 hunks)
  • packages/logger-plugin-stdout/tests/stdout-plugin.spec.ts (6 hunks)
  • packages/logger-plugin-stdout/tests/test-utils.ts (0 hunks)
  • packages/logger/src/core/logger.ts (7 hunks)
  • packages/logger/src/types/type-logger.ts (1 hunks)
  • packages/logger/tests/ctx.spec.ts (2 hunks)
  • packages/logger/tests/error.spec.ts (1 hunks)
  • packages/logger/tests/logger.spec.ts (6 hunks)
  • packages/logger/tests/test-utils.ts (0 hunks)
💤 Files with no reviewable changes (3)
  • packages/logger-plugin-stdout/tests/test-utils.ts
  • packages/logger-plugin-console/tests/test-utils.ts
  • packages/logger/tests/test-utils.ts
🧰 Additional context used
🧬 Code Graph Analysis (2)
packages/logger/src/core/logger.ts (1)
packages/logger/src/types/type-message.ts (1)
  • RawLoggerMessage (37-39)
packages/logger/src/types/type-logger.ts (1)
packages/logger/src/types/type-message.ts (1)
  • RawLoggerMessage (37-39)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: deploy (20.x)
🔇 Additional comments (34)
packages/logger/tests/error.spec.ts (1)

35-39: LGTM! Proper async/await implementation.

The logger method calls are now correctly awaited, properly implementing the async support while maintaining the existing error handling test logic.

packages/logger/tests/ctx.spec.ts (2)

31-31: LGTM! Consistent async implementation.

The logger method call is now properly awaited, correctly implementing the async support feature while preserving the context testing logic.


75-75: LGTM! Consistent async implementation.

The logger method call is now properly awaited, maintaining consistency with the async support implementation across both test cases.

packages/logger-plugin-stdout/tests/stdout-plugin.spec.ts (6)

26-26: LGTM! Proper async implementation for disabled plugin test.

The logger method call correctly implements async/await pattern while testing plugin disable functionality.


39-39: LGTM! Consistent async implementation for info level.

The logger.info() call is properly awaited, maintaining consistency with the async support feature.


55-59: LGTM! Proper async implementation for warn level.

The logger.warn() call with object message is correctly awaited, implementing the async support consistently.


77-81: LGTM! Consistent async implementation for debug level.

The logger.debug() call is properly awaited, maintaining consistency with the async support implementation.


99-103: LGTM! Proper async implementation for verbose level.

The logger.verbose() call is correctly awaited, implementing the async support feature consistently.


127-131: LGTM! Consistent async implementation for error level.

The logger.error() call is properly awaited, completing the comprehensive async support implementation across all log levels.

.changeset/long-meals-cross.md (1)

1-7: LGTM! Properly formatted changeset.

The changeset correctly documents the async support feature as patch-level changes across all affected packages with an appropriate description.

packages/logger-plugin-console/tests/console-plugin.spec.ts (6)

24-24: LGTM! Proper async logger usage.

The test correctly awaits the logger call, aligning with the new asynchronous logger interface.


37-37: LGTM! Proper async logger usage.

The test correctly awaits the logger call, aligning with the new asynchronous logger interface.


53-57: LGTM! Proper async logger usage.

The test correctly awaits the logger call, aligning with the new asynchronous logger interface.


75-79: LGTM! Proper async logger usage.

The test correctly awaits the logger call, aligning with the new asynchronous logger interface.


97-101: LGTM! Proper async logger usage.

The test correctly awaits the logger call, aligning with the new asynchronous logger interface.


125-129: LGTM! Proper async logger usage.

The test correctly awaits the logger call, aligning with the new asynchronous logger interface.

packages/logger/tests/logger.spec.ts (6)

5-5: LGTM! Cleanup of unused test utility.

The removal of the sleep import is appropriate since logger calls are now properly awaited.


50-54: LGTM! Proper async logger usage.

All logger method calls are correctly awaited, ensuring proper test execution flow with the new asynchronous interface.


91-95: LGTM! Consistent async pattern.

The logger calls are properly awaited across multiple plugins, maintaining test reliability.


141-165: LGTM! Comprehensive async conversion.

All object-style logger calls are properly awaited, ensuring the pipeline completes before assertions.


220-243: LGTM! Function message handling with async support.

The function-style logger calls are correctly awaited, which is crucial for proper error handling and context resolution.


301-309: LGTM! Pipeline plugin async compatibility.

The logger calls in pipeline plugins are properly awaited, maintaining consistency across the logging architecture.

packages/logger/src/core/logger.ts (7)

15-15: LGTM! Fixed interface name typo.

The correction from LogggerType to LoggerType fixes the import reference.


30-30: LGTM! Consistent interface implementation.

The class now correctly implements the properly named LoggerType interface.


157-163: LGTM! Proper async implementation.

The debug method is correctly converted to async and awaits the pipeline execution, enabling proper asynchronous logging behavior.


169-175: LGTM! Consistent async pattern.

The info method follows the same async pattern as the other logging methods.


181-187: LGTM! Consistent async pattern.

The warn method follows the same async pattern as the other logging methods.


193-199: LGTM! Consistent async pattern.

The error method follows the same async pattern as the other logging methods.


205-211: LGTM! Consistent async pattern.

The verbose method follows the same async pattern as the other logging methods.

packages/logger/src/types/type-logger.ts (5)

208-208: LGTM! Core async interface change.

The debug method signature correctly returns Promise<void> to support asynchronous logging operations.


214-214: LGTM! Consistent async interface.

The info method signature matches the async pattern established for all logging methods.


220-220: LGTM! Consistent async interface.

The warn method signature matches the async pattern established for all logging methods.


226-226: LGTM! Consistent async interface.

The error method signature matches the async pattern established for all logging methods.


232-232: LGTM! Consistent async interface.

The verbose method signature matches the async pattern established for all logging methods.

@tianyingchun tianyingchun merged commit 2d78605 into hyperse-io:main Aug 6, 2025
3 checks passed
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.

2 participants