It is possible with monkey patching by creating an initializer like this:
class Rails::Rack::Logger < ActiveSupport::LogSubscriber
protected
def before_dispatch(env)
request = ActionDispatch::Request.new(env)
info “\n\nStarted #{request.request_method} "#{request.url}" for #{request.ip} at #{Time.now.to_default_s}”
end
end
Would there be any interest in having something like this, configurable, in Rails? (I did patches for Rails that never managed to gather enough popularity and were ignored, I’m not wasting my time again)
I wouldn’t know, seems like it could be a somewhat common use case. I was just tryin’ to help
In any case, I don’t know about making it a patch, but you could make it into a plugin and stick it on github and rubyforge. You’d be able to use it from multiple apps easily, and if there is interest in it, people can use it and contribute and whatnot.
Off-topic, making code like that reusable and public is never a waste of time, imo. Every once in a while I’ll get a thank-you or a feature request for some little util I wrote, pushed public, and forgot – and it’s pretty neat.
Yes, I make re-usable code all the time… I released many gems and I have lot’s of github repos. The part that was a waste of time was creating a patch for Rails.
It is possible with monkey patching by creating an initializer like this:
I'm not entirely sure what you're trying to do, but there's nothing
stopping you creating your own log subscriber, attaching it to the
relevant events and log whatever you want