fittinq/logger-elasticsearch

There is no license information available for the latest version (5.2.2) of this package.

5.2.2 2023-12-15 11:59 UTC

This package is auto-updated.

Last update: 2024-04-15 12:53:54 UTC


README

This library gives a framework to log to ElasticSearch. It has a few concepts that might look weird at first glance.

Connect to ElasticSearch

First we connect to elastic search with the client builder. You can set this up in your service.yml as follows


Fittinq\Logger\Elastic\ClientBuilder:
    arguments:
        - '%env(ELASTIC_LOGGER_HOST)%'

Indices

The ElasticSearch logger must write its message to a given index. Because you might want to decide you want an index by day, or an index by the alphabet we introduced the IndexResolver.

To get you going we added a IndexResolver class that simply names the index by any name that you pass to its constructor. We provided a second resolver called DateIndex which suffixes the given name with the date in yyyymmdd format.

These can be added to your project by wiring them as follows:

Fittinq\Logger\Index\IndexResolver:
    arguments:
        - 'my_index'

or


Fittinq\Logger\Index\DateIndex:
    arguments:
        - 'prefix_%env(APP_ENV)%'
        - '_Ymd'
        

Context

When you log a message, you probably might want to add some context. Such as which service initiated the log message. You can provide context where you log the message since PSR-3 supports this. However, this might be inconvenient. You might not have the right data at hand. For instance, you don't want to have every class that logs a message know what the service they're in is called. In fact, you might not even be able to add that to a class if it comes from another library.

We use the ContextResolver for this. You can use this to set up logic that is added to the context every time you log something.

Fittinq\Logger\Context\ContextResolver:
    arguments:
        - { arg1: 'myvalue', arg2: 'myvalue2' }

Set up the actual logger

Then we tie all pieces together:

   Fittinq\Logger\Logger\ElasticSearchLogger:
        arguments:
            - '@Fittinq\Logger\Elastic\ClientBuilder'
            - '@Fittinq\Logger\Index\DateIndex'
            - '@Fittinq\Logger\Context\ContextResolver'