silencer icon indicating copy to clipboard operation
silencer copied to clipboard

Rails 5 status?

Open johnnaegle opened this issue 7 years ago • 6 comments

All the tests pass with Rails 5, but when I include this gem in my upgraded rails 5 project, all requests stop logging shortly after the server starts (perhaps after the first silenced request). Has this been used successfully on a Rails 5 project?

I ended up rolling my own middleware that just inspects the HTTP_X_SILENCE_LOGGER which was the only way I was silencing requests.

class Rails::Rack::RequestSilencer
  attr_reader :app, :options

  def initialize(app, options={})
    @app = app
    @options = options
  end

  def silent_header?(env)
    env['HTTP_X_SILENCE_LOGGER']
  end

  def call(env)
    if silent_header?(env)
      ::Rails.logger.silence { @app.call(env) }
    else
      app.call(env)
    end
  end
end

johnnaegle avatar Dec 08 '16 17:12 johnnaegle

hi @johnnaegle I haven't tried it on a Rails 5 app myself yet, but your experience is a bit worrisome. I'll see if I can't figure out what's going on here.

stve avatar Dec 09 '16 18:12 stve

@johnnaegle I added silencer to one of my Rails 5 apps and did some testing locally. I couldn't identify anything out of the ordinary and from what I could tell it was working alright. Now, this is hardly a valid or extensive test and I'll give more credence to your report over my limited attempt to reproduce. I wonder if Rails.logger.silence isn't actually threadsafe afterall. Were you using puma?

Despite this issue, I opted to release 1.0.0 primarily because I'd been sitting on 1.x for so long and more issues were being reported as the result of use of the significantly outdated 0.6.0 release.

I'll take another stab at reproducing this. If you have any thoughts or suggestions, they are most welcome 😄

stve avatar Feb 15 '17 05:02 stve

I believe this is still an issue. I am using puma. Did anybody have a chance to take a look and try to 'bridge' this issue?

darkodosenovic avatar May 11 '17 21:05 darkodosenovic

Works for me on 5.1.2, both in development and production. Also using puma.

jtippett avatar Jul 14 '17 12:07 jtippett

Its not working for me with Puma in development.

omenking avatar Oct 01 '18 15:10 omenking

FWIW, I was experiencing this problem on a Rails 5.2.4.5 app running with Puma 5.2.2 under JRuby 9.2.14.0 when I was using:

config.logger = Logger.new(STDOUT)

In conjunction with Puma's stdout_redirect in my Puma config (previously I'd needed to use STDOUT logging to work with a Tomcat deployment strategy before Rails 5). After switching the production config.logger to use ActiveSupport::Logger.new("#{Rails.root}/log/production.log") and having the Puma stdout_redirect just handle Puma's own output, the main logfile now continues to be written as expected with silencer enabled.

ryanfb avatar Mar 25 '21 13:03 ryanfb