承接 fittinq/logger-elasticsearch 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fittinq/logger-elasticsearch

最新稳定版本:7.0.0

Composer 安装命令:

composer require fittinq/logger-elasticsearch

包简介

README 文档

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'

统计信息

  • 总下载量: 6.38k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2019-12-05