I am currently developing a Symfony 2 Application and I want to log when some setters are called in my Models.
As I see, there is no way to inject the logger by default or access it via a static registry in Symfony 2, so my approach is as follows:
I added a static method and property to the base class of my models and set the Logger there. I also added a getter, that is then available in my models.
I set the logger in there via the request kernel event, so the logger is only available after this event.
This solution works but it seems rather hacky to me. Anyone got a better idea how to approach this? A setup method that does not rely on the request kernel event would be nice. A method that does not rely on static properties would be even nicer!
Attention! Adding the logger to the base document may lead to issues with serialization.