Report this

What is the reason for this report?

Exclude load balancer logs in Symfony 4.1

Posted on January 7, 2020
Juri

By Juri

Hello i have a route like this in symfony app for health checks in digital ocean load balancer:

/**
    * Status page. It is accessible only internally from within the network
    *
    * @Route("/status", name="index_status", methods={"GET"})
    *
    * @param Request $request
    *
    * @return Response
    */
   public function statusAction(Request $request): Response
   {
       return new Response('Happy PDF printing');
   }

And my monolog configuration looks like this:

monolog:
    handlers:
        main:
            type: 'fingers_crossed'
            channels: ['!security']
            action_level: info
            excluded_http_codes: [403, 404, {200: ['^/ping(.+)', '^/status(.+)', '^/status?q=%2Fstatus', '^cloud.digitalocean.com/status?q=%2Fstatus']}]
            handler: file
        file:
            type: stream
            level: debug
            path: "%kernel.logs_dir%/app.log"
            formatter: Monolog\Formatter\JsonFormatter
            include_stacktraces: true

However i can’t make monolog to not save logs about status requests from load balancer, they are made with request_uri like this http://cloud.digitalocean.com/status?q=%2Fstatus. Any idea if it’s possible to exclude them from symfony app?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

I think that it might be because of the GET parameters in your status route: /status?q=%2Fstatus, maybe it is a good idea to try and change the route so that it does not require a get parameter, that way the excluded_http_codes rules should work.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.