Last active
October 13, 2025 20:32
-
-
Save cannikin/1ce9fc5838fa1e8b1e6a542dda718d1a to your computer and use it in GitHub Desktop.
Initializer to attempt to revert development logging using Falcon + Rails back to Rails default
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
# Disable console-adapter-rails and restore standard Rails logging | |
# The falcon-rails gem automatically includes console-adapter-rails which | |
# overrides Rails' default logging format. This initializer restores the | |
# standard Rails logging behavior including request logging. | |
if Rails.env.development? | |
Rails.application.configure do | |
# Set up standard Rails logging before Falcon takes over | |
config.logger = ActiveSupport::Logger.new($stdout) | |
config.log_level = :debug | |
config.log_formatter = ActiveSupport::Logger::SimpleFormatter.new | |
# This runs after Rails is fully initialized but before requests start | |
config.to_prepare do | |
# Only override if Rails.logger exists and we're not in the middle of startup | |
if defined?(Rails.logger) && Rails.logger | |
# Create a new standard Rails logger | |
logger = ActiveSupport::Logger.new($stdout) | |
logger.level = :debug | |
logger.formatter = ActiveSupport::Logger::SimpleFormatter.new | |
# Replace Rails.logger with our standard logger | |
Rails.logger = logger | |
# Update Rails component loggers to use the same logger | |
ActiveRecord::Base.logger = logger if defined?(ActiveRecord::Base) | |
ActionController::Base.logger = logger if defined?(ActionController::Base) | |
ActionView::Base.logger = logger if defined?(ActionView::Base) | |
ActionMailer::Base.logger = logger if defined?(ActionMailer::Base) | |
ActiveJob::Base.logger = logger if defined?(ActiveJob::Base) | |
# Update log subscribers to use our logger | |
ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber| | |
subscriber.logger = logger if subscriber.respond_to?(:logger=) | |
end | |
# Force ActionView logging to work by completely resetting it | |
if defined?(ActionView::LogSubscriber) | |
# Detach any existing ActionView subscribers that might be using Console logger | |
ActiveSupport::Notifications.unsubscribe("render_template.action_view") | |
ActiveSupport::Notifications.unsubscribe("render_partial.action_view") | |
ActiveSupport::Notifications.unsubscribe("render_collection.action_view") | |
# Set the logger for ActionView::LogSubscriber | |
ActionView::LogSubscriber.logger = logger | |
# Re-attach ActionView logging with our logger | |
ActionView::LogSubscriber.attach_to :action_view | |
end | |
# Force ActionController logging to work | |
if defined?(ActionController::LogSubscriber) | |
ActiveSupport::Notifications.unsubscribe("start_processing.action_controller") | |
ActiveSupport::Notifications.unsubscribe("process_action.action_controller") | |
ActionController::LogSubscriber.logger = logger | |
ActionController::LogSubscriber.attach_to :action_controller | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment