Question

Exclude load balancer logs in Symfony 4.1

Posted January 7, 2020 711 views
PHP FrameworksLoad BalancingLogging

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?

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.

×
1 answer

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.

Submit an Answer