Class: SafePgMigrations::VerboseSqlLogger
- Inherits:
-
Object
- Object
- SafePgMigrations::VerboseSqlLogger
- Defined in:
- lib/safe-pg-migrations/plugins/verbose_sql_logger.rb
Instance Method Summary collapse
Instance Method Details
#setup ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/safe-pg-migrations/plugins/verbose_sql_logger.rb', line 5 def setup @activerecord_logger_was = ActiveRecord::Base.logger @verbose_query_logs_was = Polyfills::VerboseQueryLogsPolyfill.verbose_query_logs @colorize_logging_was = ActiveRecord::LogSubscriber.colorize_logging disable_marginalia if defined?(Marginalia) stdout_logger = Logger.new($stdout, formatter: ->(_severity, _time, _progname, query) { "#{query}\n" }) ActiveRecord::Base.logger = stdout_logger ActiveRecord::LogSubscriber.colorize_logging = colorize_logging? # Do not output caller method, we know it is coming from the migration Polyfills::VerboseQueryLogsPolyfill.verbose_query_logs = false self end |
#teardown ⇒ Object
20 21 22 23 24 25 |
# File 'lib/safe-pg-migrations/plugins/verbose_sql_logger.rb', line 20 def teardown Polyfills::VerboseQueryLogsPolyfill.verbose_query_logs = @verbose_query_logs_was ActiveRecord::LogSubscriber.colorize_logging = @colorize_logging_was ActiveRecord::Base.logger = @activerecord_logger_was enable_marginalia if defined?(Marginalia) end |