How to use logger method of TestProf Package

Best Test-prof_ruby code snippet using TestProf.logger


Source:logging.rb Github


Full Screen

...4 module Rails5 # Add `with_logging` and `with_ar_logging helpers`6 module LoggingHelpers7 class << self8 attr_writer :logger9 def logger10 return @logger if instance_variable_defined?(:@logger)11 @logger = end13 def ar_loggables14 return @ar_loggables if instance_variable_defined?(:@ar_loggables)15 @ar_loggables = [16 ::ActiveRecord::Base,17 ::ActiveSupport::LogSubscriber18 ]19 end20 # rubocop:disable Metrics/CyclomaticComplexity21 # rubocop:disable Metrics/PerceivedComplexity22 def all_loggables23 return @all_loggables if instance_variable_defined?(:@all_loggables)24 @all_loggables = [25 ::ActiveSupport::LogSubscriber,26 ::Rails,27 defined?(::ActiveRecord::Base) && ::ActiveRecord::Base,28 defined?(::ActiveJob::Base) && ::ActiveJob::Base,29 defined?(::ActionView::Base) && ::ActionView::Base,30 defined?(::ActionMailer::Base) && ::ActionMailer::Base,31 defined?(::ActionCable::Server::Base.config) && ::ActionCable::Server::Base.config,32 defined?(::ActiveStorage) && ::ActiveStorage33 ].compact34 end35 # rubocop:enable Metrics/CyclomaticComplexity36 # rubocop:enable Metrics/PerceivedComplexity37 def swap_logger(loggables)38 do |loggable|39 was_logger = loggable.logger40 loggable.logger = logger41 was_logger42 end43 end44 def restore_logger(was_loggers, loggables)45 loggables.each_with_index do |loggable, i|46 loggable.logger = was_loggers[i]47 end48 end49 end50 # Enable verbose Rails logging within a block51 def with_logging52 *loggers = LoggingHelpers.swap_logger(LoggingHelpers.all_loggables)53 yield54 ensure55 LoggingHelpers.restore_logger(loggers, LoggingHelpers.all_loggables)56 end57 def with_ar_logging58 *loggers = LoggingHelpers.swap_logger(LoggingHelpers.ar_loggables)59 yield60 ensure61 LoggingHelpers.restore_logger(loggers, LoggingHelpers.ar_loggables)62 end63 end64 end65end66if TestProf.rspec?67 RSpec.shared_context "logging:verbose" do68 around(:each) do |ex|69 with_logging(&ex)70 end71 end72 RSpec.shared_context "logging:active_record" do73 around(:each) do |ex|74 with_ar_logging(&ex)75 end76 end77 RSpec.configure do |config|78 config.include TestProf::Rails::LoggingHelpers79 config.include_context "logging:active_record", log: :ar80 config.include_context "logging:verbose", log: true81 end82end83TestProf.activate("LOG", "all") do84 TestProf.log :info, "Rails verbose logging enabled"85 ActiveSupport::LogSubscriber.logger =86 Rails.logger =87 ActiveRecord::Base.logger = TestProf::Rails::LoggingHelpers.logger88end89TestProf.activate("LOG", "ar") do90 TestProf.log :info, "Active Record verbose logging enabled"91 ActiveSupport::LogSubscriber.logger =92 ActiveRecord::Base.logger = TestProf::Rails::LoggingHelpers.logger93end...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:


You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Test-prof_ruby automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?