定制 mediasuite/silverstripe-logging-elasticsearch 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

mediasuite/silverstripe-logging-elasticsearch

Composer 安装命令:

composer require mediasuite/silverstripe-logging-elasticsearch

包简介

A modification of monologs public logging handler to allow Elastic Search to work with Silverstripe 4 project and the latest elasticsearch version on the Cloud

README 文档

README

Out of the box Silverstripe uses a package called monolog as its “ready to go” logging solution. Monolog seems to be ubiquitous for PHP logging in multiple frameworks and is well supported..

You can specify a handler from a folder of handlers that connects to an interface for a wide range of logging approaches into a Slack channel, Stream into a logging file (most common approach), write to DB etc.

One of these handlers is designed for ElasticSearch. However due to SS4 restricting requirement to monolog v1.2.7.1 there are some minor complications.

How it works

We have the monolog package which is used to bridge the SS specific framework internal errors/logs and converts into the PSR4 compatible standard, then hands this over to a client that handles the request/response to the ElasticSearch cloud instance.

This client is a package named elastica which binds the output of the logging from monolog to a curl request to the cloud instance. Another code base that is very popular in php community. Though seems to be redundant in later versions of monolog.

*In silverstripe 5 we can use monolog v3.4.1 which handles this all natively with the API provided from ElasticSearch. This will mitigate the need for the custom code described in the solution.

The older releases of elastica are not compatible with the Cloud ES api. However upgrading elastica then creates issues with the older version monolog v1.2.1.7 codebase.

Most notably the “code formatter” references methods that are now deprecated and removed from the elastica codebase.

Installation

composer require mediasuite/silverstripe-logging-elasticsearch

Add the following code snippit to your _config.php with the 3 ENV varaibles set in your .env based on your ES cloud instance config

app/_config.php


$logger = Injector::inst()->get(LoggerInterface::class);
if ($logger instanceof Logger
    && Environment::getEnv('ELASTIC_SEARCH_INDEX')
    && Environment::getEnv('ELASTIC_SEARCH_HOST')
    && Environment::getEnv('ELASTIC_SEARCH_APIKEY')) {
    $options = array(
        'index' => Environment::getEnv('ELASTIC_SEARCH_INDEX')      // Elastic index name
    );
    $config = [
        'connections' => [
            [   'host' => Environment::getEnv('ELASTIC_SEARCH_HOST'),
                'port' => 443,
                'transport' => 'Https',
                'headers' => [
                'Authorization' => 'ApiKey' . Environment::getEnv('ELASTIC_SEARCH_APIKEY')
                ]
            ]
        ]
    ];
    $client = new Client($config);
    $handler = new CustomESHandler($client, $options);
    $logger->pushHandler($handler);
}

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-07-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固