Can someone share a .services.yml entry for the use of ElasticsearchHandler

Created on 8 July 2022, almost 2 years ago
Updated 17 August 2023, 10 months ago

Hi guys,

I would be very thankful if someone could share a bit how exactly should be configured a monolog logging to an elasticsearch.

I assume we have to use the Monolog\Handler\ElasticsearchHandler

Here the starting point:

parameters:
  monolog.channel_handlers:
    default:
      handlers: ['elastic']
      formatter: 'json'

services:

  monolog.handler.elastic:
    class: Monolog\Handler\ElasticsearchHandler
    # arguments: []

what I see from vendor/monolog/monolog/src/Monolog/Handler/ElasticsearchHandler.php is that the two paramethers:

* @param Client $client Elasticsearch Client object
* @param mixed[] $options Handler configuration

which means that the two arguments should be the client and the second the options.

Can someone give me an example of how exactly I could configure everything inside of the services.yml file?

Thank you in advance

💬 Support request
Status

Active

Version

2.0

Component

Documentation

Created by

🇩🇪Germany Nikolay Borisov

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇺🇸United States chadedge

    Hey bud, here's what I did.
    1. In `parameters` section of services.yml:

      monolog.channel_handlers:
        default:
          handlers:
            - name: 'elasticsearch'
              formatter: 'elasticsearch'
            - name: 'rotating_file'

    (Yes, that means I'm routing to Elasticsearch _and_ a local rotating file - this is my local environment so I wanted some double-coverage as I played with log levels)

    2. In `services` section of services.yml:

    services:
      monolog.handler.elasticsearch:
        class: Monolog\Handler\ElasticaHandler
        arguments: ['@elastica.client', {'index': 'brandname_local'}, '%monolog.level.notice%']
      elastica.client:
        class: Elastica\Client
        arguments: ['http://elasticsearch:9200']
        # arguments: ['https://vpc-test-logging-an_aws_instance_name_here_for_testing_remote_logging:443']

    (I have a commented out argument for the hostname with port so I can swap from logging to a local instance of ES vs an AWS instance)

    I think the thing missing from your comment was the `elastica.client` that your handler needed to reference. I tried with the elasticsearch.client but that needed an additional `resolver` and boyo that went down a failure rabbit-hole.

  • 🇮🇳India Shreya_98

    I configured ElasticsearchHandler inside service.yml file. Kindly review this patch file.

Production build 0.69.0 2024