# Request start log messages should use ActiveSupport::LogSubscriber in Rails::Rack::Logger

**URL:** <https://discuss.rubyonrails.org/t/request-start-log-messages-should-use-activesupport-logsubscriber-in-rails-logger/83247>\
**Category:** rubyonrails-core\
**Tags:** rack, actiondispatch\
**Created:** [July 14, 2023, 3:22pm UTC](https://discuss.rubyonrails.org/t/request-start-log-messages-should-use-activesupport-logsubscriber-in-rails-logger/83247 "2023-07-14T15:22:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sled](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/sled/32/9988_2.png) [@sled](https://discuss.rubyonrails.org/u/sled)\
**Post date:** [July 14, 2023, 3:22pm UTC](https://discuss.rubyonrails.org/t/request-start-log-messages-should-use-activesupport-logsubscriber-in-rails-logger/83247/1 "2023-07-14T15:22:18Z")

</div>

Currently the following log message

```ruby
Started GET "/something" for 127.0.0.1 at 2023-07-14 09:52:04 +0200" 

```

is directly logged in `Rails::Rack::Logger` using `Rails.logger.info` in [railties/lib/rails/rack/logger.rb](https://github.com/rails/rails/blob/main/railties/lib/rails/rack/logger.rb#L54-L60)

This poses a problem when you want to switch to structured logs (JSON), logging libraries like SemanticLogger and LogRage override this class because of this. There is currently no way of preventing or modifying this log message without patching `Rails::Rack::Logger`.

I’d like to propose that we should use ActiveSupport::LogSubscriber for this with an `Evented` LogSubscriber, this can be done by extending [actionpack/lib/action\_dispatch/log\_subscriber.rb](https://github.com/rails/rails/blob/main/actionpack/lib/action_dispatch/log_subscriber.rb) with something like:

```ruby
module ActionDispatch
  class LogSubscriber < ActiveSupport::LogSubscriber
     # existing code ...

     def self.attach_to(*)
       ActiveSupport::Notifications.subscribe('request.action_dispatch', Request.new)

       super
     end

     class Request
       def start(name, _id, payload)
         return unless logger&.info?

         request = payload[:request]

         logger.info(
           sprintf(
             'Started %s "%s" for %s at %s',
              request.raw_request_method,
              request.filtered_path,
              request.remote_ip,
              Time.now
           )
         )
       end

       def finish(_name, _id, _payload); end

       def logger
         Rails.logger
       end
    end
  end
end

```

A similar approach is used in ActionView’s log subscriber in [actionview/lib/action\_view/log\_subscriber.rb](https://github.com/rails/rails/blob/main/actionview/lib/action_view/log_subscriber.rb#L76-L106)

If you support this change I can contribute the change with tests.
