quiet_assets icon indicating copy to clipboard operation
quiet_assets copied to clipboard

Missing logs with Puma

Open dunghuynh opened this issue 11 years ago • 10 comments

After adding this gem, the development environment using Puma server miss all logs. (There is only logs for the first request)

Thank you.

dunghuynh avatar Apr 11 '15 10:04 dunghuynh

:+1: same here ... second request stops logging :<

grosser avatar May 15 '15 03:05 grosser

@route

grosser avatar May 15 '15 03:05 grosser

Like I said in a previous thread I use it myself, no probs. Give me reproducible app and I'll work it out

route avatar May 15 '15 06:05 route

only happens in apps with lots of assets on multithreaded puma

solution is making rails logger level thread safe ...

inspired by http://log.kares.org/2011/04/railslogger-is-not-threadsafe.html

ActiveSupport::Logger.class_eval do
  def level
    Thread.current[thread_hash_level_key] || @level
  end

  def level=(level)
    Thread.current[thread_hash_level_key] = level
  end

  private

  def thread_hash_level_key
    @thread_hash_level_key ||= :"ActiveSupport::Logger:#{object_id}"
  end
end

grosser avatar May 17 '15 21:05 grosser

a better solution would be for puma to use a new logger for each thread ... or rails doing that ...

grosser avatar May 17 '15 21:05 grosser

tried adding

Rails.logger = Rails.logger.dup to pumas on_worker_boot ... but the puma config is not loaded when doing rails s so that's not helpful ...

grosser avatar May 17 '15 21:05 grosser

with this patch the rails log stops disappearing ... but now I see that quiet assets did not actually work / it still shows assets ... maybe I'll play more with this later ...

grosser avatar May 17 '15 22:05 grosser

I'd caught in this issue while was tried to move to puma server. Wasted a couple hours trying to synchronize a reset of log level, however the best I could do is to fix a level resetting in the ensure clause to Rails.application.config.log_level There is the fork: https://github.com/tinbka/quiet_assets

tinbka avatar Nov 10 '15 00:11 tinbka

seems this is still a problem? hard to use puma if logging is not working.

emiltin avatar Mar 15 '16 21:03 emiltin

@emiltin, I've ended up implementing this feature in my own logger. See https://github.com/tinbka/tracee

tinbka avatar Mar 15 '16 22:03 tinbka