Everything is in the title but for the sake of it:
The company I work for has a really big Ruby On Rails app. After years of development we realized it lacked of logging. Production incidents were sometimes really hard to track and consequently to resolve.
So there was that issue in our backlog to improve the whole logging system.
I started added custom loggers for classes here and there, when really required but it seemed kind of dumb to copy / paste that piece of logic everywhere.
So i wondered: How to properly create dedicated loggers for desired Ruby on Rails classes, in a nice, compact and generic way ?
The answer for me was the use of
ActiveSupport::Concern.The code is easily understandable and commented so I think just pasting it here will make the best of explanations:
The code comments say it all. Nothing groundbreaking here but I also think that is a really good example of a proper use of
ActiveSupport::Concern. I often see it used as a way to split models/controllers that get too big into different logical bricks (which may not be wrong neither) but i feel this kind of generic way to add a possibility to any class is more like it's meant to be used (or am I wrong ?).Feel free to debate, hope this helps :)