shadabahmed / logstasher

Awesome rails logs
MIT License
817 stars 136 forks source link

suppress_app_log: true prevent DB timing to be emited #137

Closed cernyjakub closed 3 years ago

cernyjakub commented 7 years ago

When I disable app log with suppress_app_log, it automatically switches all :db fields to be 0.

Rails 5.0.3. Happens both in development and production modes.

Anyway, thanks for great gem.

kyrylo commented 5 years ago

We also ran into this and it's quite important for us to fix this issue.

kyrylo commented 5 years ago

I fixed it in https://github.com/shadabahmed/logstasher/pull/148. In the meantime, we will depend on our fork with the fix, since we can't afford waiting.

ibrahima commented 1 year ago

Hmm, does the db timing depend on config.logstasher.record_enabled? I have that set to false because I don't need the full SQL statements logged, but it seems like with that set to false I don't get DB timings either.

babatakao commented 1 year ago

I have same issue on latest version (v2.1.5) with both rails 6.1 and 7.0. DB timing seems depends on either record_enabled:true or suppress_app_log:false, otherwise it always be 0.0.

babatakao commented 1 year ago

I've found a workaround.

  class CustomLogSubscriber < ActiveRecord::LogSubscriber
    def sql(event)
      self.class.runtime += event.duration
    end
  end
  CustomLogSubscriber.attach_to :active_record

Note that this might be broken after Rails 7.1 by https://github.com/rails/rails/pull/46041

ibrahima commented 1 year ago

Yeah looking at it now it seems like the log subscriber just won't be attached unless using those other options. It might be nice to have additional options if you want to log timing information but not the raw SQL or the view logs.