Complete the code to log an info message in Rails.
Rails.logger.[1]("User signed in successfully")
The info method logs informational messages, which are useful for general application events.
Complete the code to set the log level to show warnings and above.
Rails.logger.level = Logger::[1]Setting the log level to WARN means only warnings, errors, and fatal messages will be logged.
Fix the error in the code to log an error message with exception details.
begin # some code rescue => e Rails.logger.[1]("Error occurred: #{e.message}") end
The error method is used to log error messages, especially exceptions.
Fill both blanks to create a custom logger that writes to a file and sets the log level to debug.
custom_logger = Logger.new([1]) custom_logger.level = Logger::[2]
Creating a logger with a file path writes logs to that file. Setting level to DEBUG logs detailed messages.
Fill all three blanks to filter logs for requests with status code 500 or higher and log the path and status.
ActiveSupport::Notifications.subscribe("process_action.action_controller") do |*args| name, start, finish, id, payload = args status = payload[[1]] path = payload[[2]] if status.to_i [3] 500 Rails.logger.error("Error at #{path} with status #{status}") end end
In Rails, the process_action.action_controller notification payload contains :status and :path keys, which can be used to monitor and log server errors (status ≥ 500).