Imagine you have a class manager to manages sending mails (be called MailManager).
In this, you have to log mails that are sent. A good solution is to transform the MailManager class into a service and then inject class for creating logs (Monolog for example) into the MailManager creating a service.
To do this :
1- Declare future MailManager class as service (in services.yml)
2- Inject logger existant service using argument method
3- Create MailManager class
4- Call MailManager in a Controller for example
This modified text is an extract of the original Stack Overflow Documentation created by following contributors and released under CC BY-SA 3.0