nzo/elk-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

nzo/elk-bundle

Composer 安装命令:

composer require nzo/elk-bundle

包简介

A Symfony bundle to manage logs on the ELK Stack

README 文档

README

Build Status Latest Stable Version

The NzoElkBundle is a Symfony Bundle used to manage the logs with the ELK stack (Elasticsearch, Logstash, Kibana).

Compatible with Symfony >= 4.4

Installation

Through Composer:

$ composer require nzo/elk-bundle

Register the bundle in config/bundles.php (without Flex):

// config/bundles.php

return [
    // ...
    Nzo\ElkBundle\NzoElkBundle::class => ['all' => true],
];

Configure your application's config.yml:

# config/packages/nzo_elk.yaml
nzo_elk:
    app_name: '%env(ELK_APP_NAME)%'
    app_environment: '%env(ELK_APP_ENVIRONMENT)%'

    log_encryptor:                               # Optional
        secret_key: '%env(ELK_LOG_SECRET)%'      # Required
        fields:                                  # Required 
            - email
            - username
            - ...


# .env
ELK_APP_NAME=app
ELK_APP_ENVIRONMENT=local            

Usage

Using the JSON formatter

In the definition of the handlers, simply add the nzo.elk.monolog.formatter formatter.

Example :

api_errors:
    type: stream
    path: '%kernel.logs_dir%/%kernel.environment%.elk_api_errors.log'
    level: errors
    channels: ['api']
    formatter: nzo.elk.monolog.formatter

Encrypt Logs

This bundle offer a secure way to encrypt sensitive data sent in the logs.

To do so, You must enable and set the log_encryptor configuration and the secret_key.

In the fields configuration you must add the logs context fields that you want to be encrypted. These fields must be shared in the ELK stack in order to enable the decryption for them.

Setup:
// config/bundles.php

return [
    // ...
    Nzo\UrlEncryptorBundle\NzoUrlEncryptorBundle::class => ['all' => true],
];
Configuration:
# config/packages/nzo_elk.yaml
nzo_elk:
    # ...
    log_encryptor:
        secret_key: '%env(ELK_LOG_SECRET)%'
        fields:
            - email
            - username
            - location.address.code



# .env
ELK_LOG_SECRET=SOME_SECRET
Usage:
public function log()
{
    $context = [
        'name' => 'Wolverine',
        'username' => 'test',
        'email' => 'test@example.fr',
        'location' => [
            'address' => [
                'code' => '75000',
                'city' => 'Paris',
                'country' => 'France'
            ]
        ]
    ];

    $this->logger->error('Error', $context);
}

// The log output will be like:
[
    'name' => 'Wolverine',
    'username' => 'FbEtXzIRop0FFK31MdC+McgbWybD...',
    'email' => 'DNXDcuQDn7LbwlgLKnAgPsn...',
    'location' => [
        'address' => [
            'code' => 'FnzOIHjMZDzDmSSC...',
            'city' => 'pdjKJBDfd2Khdfkhbfk....',
            'country' => 'France'
        ]
    ]
]

License

This bundle is under the MIT license. See the complete license in the bundle:

See LICENSE

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固