Skip to content

add wrapper method to call mc.cfg.Logger #1563

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 1 commit into from
Mar 16, 2024

Conversation

methane
Copy link
Member

@methane methane commented Mar 16, 2024

Description

This is just a code cleanup. I will backport this to 1.8 too.

Checklist

  • Code compiles correctly
  • Created tests which fail without the change (if possible)
  • All tests passing
  • Extended the README / documentation, if necessary
  • Added myself / the copyright holder to the AUTHORS file

Summary by CodeRabbit

  • Refactor
    • Centralized logging within the MySQL connection handling to improve error reporting and logging consistency.

Copy link

coderabbitai bot commented Mar 16, 2024

Walkthrough

The recent modifications involve consolidating logging operations across several files (auth.go, connection.go, packets.go, and statement.go) into centralized methods within the mysqlConn and mysqlStmt structs. This change streamlines the logging process, making error handling, connection closure, and logging behavior more uniform and manageable throughout the codebase.

Changes

Files Change Summary
auth.go, connection.go, packets.go Replaced direct Logger calls with a centralized log method in the mysqlConn struct.
statement.go Changed logging to use a log method within stmt.mc, affecting Exec and query methods.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • Generate unit-tests for this file.
    • 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 generate unit tests for this file.
    • @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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@coveralls
Copy link

Coverage Status

coverage: 82.003% (+0.01%) from 81.989%
when pulling a9ab807 on methane:easy-logger
into 8a327a3 on go-sql-driver:master.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8a327a3 and a9ab807.
Files selected for processing (4)
  • auth.go (1 hunks)
  • connection.go (9 hunks)
  • packets.go (12 hunks)
  • statement.go (2 hunks)
Additional comments: 25
statement.go (2)
  • 54-54: The change to use stmt.mc.log(ErrInvalidConn) centralizes logging, which is a good practice. Ensure that the log method in mysqlConn is implemented to handle various log message types effectively.
  • 98-98: Similar to the change in the Exec method, using stmt.mc.log(ErrInvalidConn) here centralizes logging. Ensure the log method in mysqlConn handles different types of log messages effectively.
auth.go (1)
  • 341-341: Changing to use mc.log("unknown auth plugin:", plugin) centralizes logging, which is beneficial. Ensure the log method in mysqlConn can handle string concatenation and variable logging effectively.
connection.go (10)
  • 48-51: The introduction of the log method in mysqlConn centralizes logging, which is a good practice. Ensure that mc.cfg.Logger is always properly initialized and supports the Print method with variadic arguments.
  • 118-118: Using mc.log(ErrInvalidConn) centralizes logging, enhancing maintainability. Ensure that log messages retain necessary context for clarity.
  • 160-160: Centralizing logging with mc.log(err) is beneficial. Verify that error contexts are preserved in log messages for effective debugging.
  • 177-177: The use of mc.log(ErrInvalidConn) for logging is consistent with the centralization effort. Ensure log messages are clear and provide sufficient context.
  • 184-184: Logging errors with mc.log(err) helps centralize logging. Check that the log method effectively handles different types of errors.
  • 218-218: Centralizing logging to mc.log(err) is a good practice. Ensure that the log messages are informative and maintain context.
  • 310-310: Using mc.log(ErrInvalidConn) for logging centralizes the logging mechanism. Confirm that all necessary context is included in log messages.
  • 370-370: The change to use mc.log(ErrInvalidConn) for logging is consistent with centralizing logging. Ensure that log messages are clear and contextual.
  • 465-465: Centralizing logging with mc.log(ErrInvalidConn) is beneficial. Verify that the log method handles context and clarity in log messages effectively.
  • 674-674: Using mc.log("closing bad idle connection: ", err) centralizes logging. Ensure that the log method can handle concatenation of strings and variables effectively.
packets.go (12)
  • 37-37: The introduction of the log method in the mysqlConn struct for logging errors is a positive change, enhancing the maintainability and consistency of logging throughout the codebase.
  • 60-60: Using the log method for logging malformed packet errors before closing the connection is consistent with the PR's objective to centralize logging. This change improves code readability and maintainability.
  • 74-74: The use of the log method for error logging here follows the PR's goal of centralizing logging. This approach simplifies the process of modifying logging behavior in the future.
  • 137-137: Logging the malformed packet error using the new log method before cleanup is in line with the PR's objectives. It ensures that logging is handled in a consistent manner across the codebase.
  • 147-147: Applying the log method for error logging in this context is appropriate and aligns with the PR's aim to centralize and standardize logging practices within the project.
  • 305-305: The use of the log method for logging errors when unable to take a buffer is consistent with the PR's goal. It centralizes logging, making it easier to manage and modify logging behavior.
  • 395-395: Employing the log method for error logging in this scenario adheres to the PR's objective of centralizing logging. This change enhances the code's maintainability.
  • 415-415: Utilizing the log method for logging errors when a buffer cannot be taken aligns with the PR's aim to centralize logging. This contributes to a more maintainable and consistent codebase.
  • 434-434: The application of the log method for error logging here is in line with the PR's objectives. It centralizes logging, facilitating easier future modifications to logging behavior.
  • 455-455: Using the log method for error logging in this context supports the PR's goal of centralizing logging. This approach simplifies logging management across the codebase.
  • 997-997: The use of the log method for logging errors when a buffer cannot be taken is consistent with the PR's objectives. It centralizes logging, enhancing code maintainability.
  • 1196-1196: Employing the log method for error logging in this scenario adheres to the PR's aim of centralizing logging. This change contributes to a more maintainable codebase.

Copy link
Contributor

@shogo82148 shogo82148 left a comment

Choose a reason for hiding this comment

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

LGTM

@methane methane merged commit 1a64773 into go-sql-driver:master Mar 16, 2024
32 checks passed
@methane methane deleted the easy-logger branch March 16, 2024 14:24
methane added a commit to methane/mysql that referenced this pull request Mar 16, 2024
methane added a commit to methane/mysql that referenced this pull request May 19, 2024
go-sql-driver#1563 broke the filename:lineno prefix in the log
message by introducing a helper function.
This commit adds the "filename:line" prefix in the helper function
instead of log.Lshortfile option to show correct filename:lineno.
methane added a commit that referenced this pull request Jun 4, 2024
#1563 broke the filename:lineno prefix in the log
message by introducing a helper function.
This commit adds the "filename:line" prefix in the helper function
instead of log.Lshortfile option to show correct filename:lineno.
methane added a commit to methane/mysql that referenced this pull request Jun 4, 2024
go-sql-driver#1563 broke the filename:lineno prefix in the log
message by introducing a helper function.
This commit adds the "filename:line" prefix in the helper function
instead of log.Lshortfile option to show correct filename:lineno.

(cherry picked from commit 2f7015e)
methane added a commit that referenced this pull request Jun 11, 2024
#1563 broke the filename:lineno prefix in the log
message by introducing a helper function.
This commit adds the "filename:line" prefix in the helper function
instead of log.Lshortfile option to show correct filename:lineno.

(cherry picked from commit 2f7015e)
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