-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add Logger to Output Query Logs #4
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contributing!
I have some comments. Please check them.
@@ -89,7 +89,7 @@ MysqlRewinder.setup(db_configs, adapter: :mysql2) | |||
If you want to use MysqlRewinder with ActiveRecord, do the following: | |||
|
|||
* Generate db_configs from `ActiveRecord::Base.configurations` | |||
* Pass `ActiveRecord::SchemaMigration.new(nil).table_name` and `ActiveRecord::Base.internal_metadata_table_name` to `DatabaseRewinder.setup` as `except_tables` | |||
* Pass `ActiveRecord::SchemaMigration.new(nil).table_name` and `ActiveRecord::Base.internal_metadata_table_name` to `MysqlRewinder.setup` as `except_tables` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
lib/mysql_rewinder/cleaner.rb
Outdated
private | ||
|
||
def log_sql(sql) | ||
return yield unless @logger.debug? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this, I understand that the logging code below is executed even if @logger
is NullLogger, that isn't desirable.
Instead, we should set @logger = nil
if logger is not passed.
Then we can write like:
def log_and_execute(sql)
return @client.execute(sql) unless @logger&.debug?
...
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Fixed for 69070ff
8a65aa8
to
a79da99
Compare
Co-authored-by: Yusuke Sangenya <[email protected]>
Co-authored-by: Yusuke Sangenya <[email protected]>
The type definition of the logger faced the same issue as described in ruby/rbs#1482, so it was set to untyped.
a79da99
to
d9542d9
Compare
Co-authored-by: Yusuke Sangenya <[email protected]>
Summary
This pull request introduces a logger to output query logs when the logger is specified in the setup. This enhancement will allow for better tracking and debugging of queries, especially during development and testing.
Changes
Other Information
Checklist