Skip to content
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

Feature Request: Suppressing server-side logs in configuration #70

Open
milkeclair opened this issue Jan 19, 2025 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@milkeclair
Copy link

milkeclair commented Jan 19, 2025

Hi, I am trying to use this gem in Rails 8!

I find this gem very useful, but when using it, I frequently see log messages related to Hotwire Spark.

To work around this, I created the following initializer.
However, I was wondering if there are any plans to support server-side log suppression in the gem’s configuration
(or if it can be done in the first place).
If such a setting already exists, please let me know.

Thanks for making a useful gem!

#config/initializers/hotwire_spark.rb

return if !defined?(Hotwire) || !defined?(Hotwire::Spark) || !Hotwire::Spark.enabled?

Hotwire::Spark.cable_server.config.logger = Logger.new(nil)
Hotwire::Spark.cable_server.config.cable = { "adapter" => "async" }

class SilentSpark < ActionController::LogSubscriber
  def start_processing(event)
    return if event.payload[:params][:hotwire_spark]
    super(event)
  end

  def process_action(event)
    return if event.payload[:params][:hotwire_spark]
    super(event)
  end
end

ActionController::LogSubscriber.detach_from :action_controller
SilentSpark.attach_to :action_controller
@jorgemanrubia
Copy link
Member

Thanks @milkeclair. I think this is a great idea. I'd be happy to a accept a PR here adding a new boolean option server_logging to turn logs on/off (default to "on"). Then, we would also rename the existing option logging to client_logging to clarify the difference.

@jorgemanrubia jorgemanrubia added the enhancement New feature or request label Jan 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants