Context:
In a rails 3 project I want to customise (heavily) the format and content of the "Processing" and "Completed in" log lines from ActionController. This is in order to have them match the (also custom) format of an older rails 2.3 app, allowing re-use of various analysis tools. Making them fixed-field (by use of place-holders where necessary) also makes it far easier to do ad-hoc queries on them with (say) awk, or to load them into a db or splunk without smart parsing.
I've achieved this goal quickly and heavy-handedly by forking rails and patching the LogSubscriber in question, but I am now looking to do it the right way.
Here's what I think I want to do:
- Create a
LogSubscriber
inheritingActionController::LogSubscriber
. - Override only the
start_processing
andprocess_action
methods. - Unsubscribe the original
ActionController::LogSubscriber
, which (sadly) registers itself as soon as the class is loaded. This is the step I'm stuck on. - Attach my custom subscriber to
:action_controller
, usingattach_to
.
I note that things would be easier if the hook-up of the default ActionController's log subscriber were done as a config step, rather than on class load.
Question:
Assuming the approach outlined above is suitable, how can I unsubscribe or unattach the default log subscriber ActionController::LogSubscriber
? The base class, ActiveSupport::LogSubscriber provides attach_to but no means of detaching.
Alternatively, what is the cleanest way of altering the behaviour of (or entirely suppressing) the two methods (start_processing, process_action) in the above mentioned class, ActionController::LogSubscriber.
Of course, I'd also welcome any other (maintainable) approach which provides full freedom in customizing the log format of the two lines mentioned.
Unsuitable approaches:
- My problem cannot be solved by adding instrumentation, as documented nicely by mnutt.
- I'd like to avoid monkey-patching, or hacking in a way that may break when the rails implementation (not interface) changes.
References:
ActiveSupport::LogSubscriber.log_subscribers
. Whether it's sufficient or safe to manipulate this directly, and at what stage in initialization, I've no idea.