Skip to content

feat: refactor logger module #122

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

Merged
merged 7 commits into from
May 16, 2025
Merged

Conversation

Flying-Tom
Copy link
Contributor

@Flying-Tom Flying-Tom commented Apr 15, 2025

What this PR does: refactor gost/log/logger module to adapt to dubbo-go logger

Which issue(s) this PR fixes:

Fixes dubbo-go #2526

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


Summary by CodeRabbit

  • New Features

    • Added support for dynamic log level adjustment when using both zap and logrus logging libraries.
  • Refactor

    • Updated logger interface and related methods to indicate success or failure when changing log levels.
    • Renamed a logger struct field for improved accessibility.
  • Style

    • Updated import aliasing for logging in test files for consistency.

@Flying-Tom
Copy link
Contributor Author

CI fix: success workflow

@Flying-Tom
Copy link
Contributor Author

apache/dubbo-go#2838 problaly need this PR to be merged, please review it.

Copy link
Member

@marsevilspirit marsevilspirit left a comment

Choose a reason for hiding this comment

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

I think the changes don't actually achieve the intended function of setting the level.
We require fewer modifications, addressing the issue with precision and clarity.

Copy link
Member

@marsevilspirit marsevilspirit left a comment

Choose a reason for hiding this comment

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

check comment.

@Flying-Tom Flying-Tom force-pushed the logger-refactor branch 5 times, most recently from a1959bf to 374a74f Compare April 20, 2025 16:26
@Flying-Tom
Copy link
Contributor Author

Error caused by the bump PR #118

@Flying-Tom Flying-Tom force-pushed the logger-refactor branch 4 times, most recently from 98da2cb to 6d0125b Compare May 10, 2025 13:33
Copy link
Member

@marsevilspirit marsevilspirit left a comment

Choose a reason for hiding this comment

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

LGTM

@AlexStocks AlexStocks requested a review from Copilot May 15, 2025 14:42
Copy link

@Copilot 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 refactors the logger module to adapt it for dubbo-go by updating the logger API and integrating logrus alongside zap. Key changes include:

  • Renaming the internal logger field from "dynamicLevel" to "DynamicLevel" (making it exported).
  • Modifying the SetLoggerLevel function to return a boolean status.
  • Updating the go.mod file with the logrus dependency and adjusting import aliases in test files.

Reviewed Changes

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

File Description
time/sleep_test.go Changed the import alias from the original package name to "gxlog".
log/logger/logger.go Updated field naming and API for setting logger level with multiple backends.
go.mod Added and adjusted the dependency for logrus.
Comments suppressed due to low confidence (2)

log/logger/logger.go:36

  • [nitpick] The renaming of 'dynamicLevel' to 'DynamicLevel' changes its visibility from unexported to exported. Please confirm that this change is intended and consistent with the module's design.
-	dynamicLevel zap.AtomicLevel
+ 	DynamicLevel zap.AtomicLevel

time/sleep_test.go:33

  • [nitpick] The change to use the alias 'gxlog' should be reviewed to ensure that all references in the test file are updated accordingly for consistency.
-	"github.com/dubbogo/gost/log"
+ 	gxlog "github.com/dubbogo/gost/log"

Copy link

coderabbitai bot commented May 15, 2025

Walkthrough

The changes introduce support for the logrus logging library in addition to the existing zap logger, allowing dynamic log level adjustment for both. The DubboLogger struct is updated for export consistency, and method signatures are modified to return a boolean indicating success. Minor import aliasing is also applied in a test file.

Changes

File(s) Change Summary
go.mod Moved logrus from indirect to direct dependency.
log/logger/logger.go Added logrus support for dynamic log level adjustment; exported DynamicLevel; updated method signatures to return success boolean.
time/sleep_test.go Added alias gxlog to the gost/log import; updated references accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Logger (OpsLogger)
    participant zap.Logger
    participant logrus.Logger

    User->>Logger: SetLoggerLevel(level)
    alt zap logger
        Logger->>zap.Logger: Parse and set level
        zap.Logger-->>Logger: Success/Failure
    else logrus logger
        Logger->>logrus.Logger: Parse and set level
        logrus.Logger-->>Logger: Success/Failure
    else Unsupported logger
        Logger-->>User: Return false
    end
    Logger-->>User: Return true/false
Loading

Poem

In the warren, logs now sing,
With zap and logrus in the ring.
Dynamic levels, set with care,
Success returned from everywhere!
A hop, a skip, a logging cheer—
The code grows stronger every year.
🐰✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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

♻️ Duplicate comments (2)
log/logger/logger.go (2)

37-37: Export DynamicLevel field for compatibility with dubbo-go.

Changing from dynamicLevel to DynamicLevel exports the field, which appears necessary for compatibility with dubbo-go as mentioned in the PR objectives.


135-152: Approve the enhanced SetLoggerLevel implementation.

The implementation now properly:

  1. Handles both zap and logrus logger types
  2. Provides appropriate error handling for level parsing
  3. Returns success/failure status for better error management

This improves compatibility with dubbo-go while maintaining robust error handling.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between e802b22 and ff353ba.

📒 Files selected for processing (3)
  • go.mod (1 hunks)
  • log/logger/logger.go (4 hunks)
  • time/sleep_test.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: ubuntu-latest - Go1.23
  • GitHub Check: ubuntu-latest - Go1.23
🔇 Additional comments (5)
time/sleep_test.go (1)

33-33: Approve the import alias addition.

Adding the gxlog alias for the log package is a good practice that makes it clear this is a custom logging package and avoids confusion with the standard library's log package.

log/logger/logger.go (4)

20-26: Approve the logrus import addition.

Adding support for the logrus logging library is a good enhancement that provides more flexibility in logger implementations and aligns with the dubbo-go logger compatibility goal.


107-107: Approve the updated field initialization.

The initialization correctly uses the renamed field DynamicLevel.


121-126: Approve the return value addition to SetLoggerLevel function.

Adding a boolean return value to indicate success/failure improves error handling and makes the API more robust.


129-132: Approve the interface update for consistency.

Updating the OpsLogger interface to match the implementation changes maintains consistency across the codebase.

@@ -12,6 +12,7 @@ require (
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/pkg/errors v0.9.1
github.com/shirou/gopsutil/v3 v3.22.2
github.com/sirupsen/logrus v1.7.0
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Approve the logrus dependency move to direct requirements.

The change correctly moves github.com/sirupsen/logrus from indirect to direct requirements, which aligns with its new direct usage in the logger implementation.


🏁 Script executed:

#!/bin/bash
# Check if there's a newer version of logrus available
curl -s https://api.github.com/repos/sirupsen/logrus/releases/latest | grep -o '"tag_name": ".*"'

# Show comparison between v1.7.0 and latest
echo "Current version is v1.7.0 (from 2020). Consider upgrading if a newer stable version is available."

Length of output: 325


Approve direct logrus dependency – consider upgrading to the latest stable

The change correctly promotes github.com/sirupsen/logrus to a direct requirement (line 15 in go.mod). However, the current version is v1.7.0 (released in 2020) and the latest stable is v1.9.3. To benefit from recent fixes and features, please bump the version in your go.mod:

• File: go.mod

- github.com/sirupsen/logrus v1.7.0
+ github.com/sirupsen/logrus v1.9.3
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
github.com/sirupsen/logrus v1.7.0
- github.com/sirupsen/logrus v1.7.0
+ github.com/sirupsen/logrus v1.9.3
🤖 Prompt for AI Agents
In go.mod at line 15, the logrus dependency is correctly moved to a direct
requirement but is pinned to an outdated version v1.7.0. Update the version to
the latest stable release, v1.9.3, by changing the version number on line 15 to
v1.9.3 to ensure you get recent fixes and features.

@AlexStocks AlexStocks merged commit e1b1aaf into dubbogo:master May 16, 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.

3 participants