Symfony 3 – Log in separate file

In Symfony, it’s pretty easy to log messages in a file. You have to use the Monolog Bundle and then follow the instructions in:

But when you want to log in a separate document, it can be quite a hustle. An easy method which I found out is the following:

Define two new services (in any services.yml ):

In the arguments of the service my_new_logger_handler  you specify the path of the new file in which you want to log.

Then, using Dependency Injection, it’s pretty easy to include that new service and log info messages:




Kommentieren Sie den Artikel