Log collection – Symfony & Phplogger

Error collection with Phplogger is fairly easy, you would need to install Phplogger client from the official page and a working Phplogger token, which can be found on the Product setup page.

In case you don’t have your development environment set up, here is a nice tutorial on the basic PHP project configuration with Docker – https://blog.phplogger.com/2019/07/11/creating-a-php-project-with-docker/


To install the Phplogger client you would need Composer dependency management. Go to your project folder and run the composer require command in the terminal.

composer require phplogger/phplogger

Next we need to locate the monolog configuration file. In Symfony 4 this is located in ./app/packages/{env}/monolog.yaml, where {env} – is dev, prod or test. You will get the most value out of Phplogger If you setup at least dev and prod environments to collect logs. Replace both configs with the following code

            type: service
            id: phplogger.handler
            channels: ["!event"]

For this to work you also need to create a special service, which will collect and process the logs, called phplogger.handler. Open your ./app/packages/services.yml file and paste the following service there

        class: PhpLogger\Monolog\PhpLoggerHandler
        arguments: ['%env(LOGGER_TOKEN)%'] # authentication token

The last thing to do is to define LOGGER_TOKEN environment variable. This can be done in the .env file or by setting it up in environment. Open ./.env file and add the following line and replace ‘b444ac06613fc8d63795be9ad0beaf550’ with your token from the Product setup page.


Good job! Now everything you log will be available to you at phplogger.com.