承接 vmorozov/laravel_fluentd_logger 相关项目开发

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

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

vmorozov/laravel_fluentd_logger

最新稳定版本:v1.1.1

Composer 安装命令:

composer require vmorozov/laravel_fluentd_logger

包简介

Provides ability to use fluentd as log driver.

README 文档

README

Latest Version on Packagist Total Downloads

This package provides ability to use fluentd as log driver. It also add additional logging capabilities such as:

  • Request log
  • DB Query log
  • Queue Jobs log
  • Log tracing

Installation

You can install the package via composer:

composer require vmorozov/laravel_fluentd_logger

You can publish the config file with:

php artisan vendor:publish --tag="laravel_fluentd_logger-config"

Add middlewares to app/Http/Kernel.php:

protected $middleware = [
    // ... other middlewares here
    \Vmorozov\LaravelFluentdLogger\Middleware\LogRequestMiddleware::class,
    \Vmorozov\LaravelFluentdLogger\Middleware\ContinueTraceMiddleware::class,
];

Add fluentd log channel to config/logging.php:

// ...some exisiting channels

'fluentd' => [
    'driver' => 'fluentd',
    'level' => env('LOG_LEVEL', 'debug'),
],

Add ENV vars with fluentd configs:

FLUENTD_HOST=127.0.0.1
FLUENTD_PORT=24224

Configuration

In config file laravel_fluentd_logger.php you can make some adjustments:

  • Disable some features
    'features_enabled' => [
        'request_log' => false,
        'db_query_log' => false,
        'queue_log' => false,
    ],
  • Overwrite default fluentd log handler
    // optionally override \Vmorozov\LaravelFluentdLogger\Logs\FluentHandler class to customize behaviour
    'handler' => SomeCustomHandler::class,
  • Change log tag format
'tagFormat' => '{{app_name}}.{{level_name}}',
  • Overwrite some options for fluentd sdk classes
    /** @see https://github.com/fluent/fluent-logger-php/blob/master/src/FluentLogger.php */
    'options' => [],

    /** @see https://github.com/fluent/fluent-logger-php/blob/master/src/PackerInterface.php */
    // specified class name
    'packer' => null,

Fluentd config samples

  • simple stdout output:
<match your_app_name_from_env.**>
  type stdout
</match>
  • output to elasticsearch + stdout:
# sendlog to the elasticsearch
# the host must match to the elasticsearch
# container service
<match your_app_name_from_env.**>
  @type copy
  <store>
    @type elasticsearch
    host elasticsearch
    port 9200
    logstash_format true
    logstash_prefix fluentd
    logstash_dateformat %Y-%m-%d
    include_tag_key true
    type_name access_log
    tag_key @log_name
    flush_interval 1s
    log_es_400_reason false
  </store>
  <store>
    @type stdout
  </store>
</match>
  • config for fluentd to accept data using port:
# bind fluentd on IP 0.0.0.0
# port 24224
<source>
  @type forward
  port 24224
  bind 0.0.0.0
</source>

More info about fluentd configuration can be found in official fluentd documentation.

Monolog processors

You can add processors to the monolog handlers by adding them to the processors array within the laravel_fluentd_logger.php config. config/laravel_fluentd_logger.php:

'processors' => [CustomProcessor::class],

CustomProcessor.php:

class CustomProcessor
{
    public function __invoke($record)
    {
        $record['extra']['level'] = $record['level_name'];
        return $record;
    }
}

Testing

composer test

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-12-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固