log request elastica client

  elastica, monolog, symfony

I am using Elastica PHP client to request my Elasticsearch index in my symfony project.

I want to log information about request sent (query data as json for example)

So i inject my monolog logger (LoggerInterface extends) in constructor and __log() method is called in request automatically and request object passed to log function : https://github.com/ruflin/Elastica/blob/6.0.0/lib/Elastica/Client.php#L726

I don’t want default format (too big and contains criticals security info), so i just need to extract data from request object, but this warning in phpdoc confuse me :

@deprecated Overwriting Client->_log is deprecated. Handle logging
functionality by using a custom LoggerInterface.

I have injected my custom logger but how to change log format without overriding __log as suggested by bundle ?

Basically if i override __log function it’s easy eg :

    protected function _log($context)
    if ($context instanceof Request) {
        $this->_logger->debug('Elastica Request', [
            'query' => $context->getQuery(),
            'method' => $context->getMethod()


Source: Symfony Questions