upaid/elk 问题修复 & 功能扩展

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

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

upaid/elk

最新稳定版本:1.0.2

Composer 安装命令:

composer require upaid/elk

包简介

ELK Logger for Laravel

关键字:

README 文档

README

Laravel logger for formatting logs for ELK.
Adds support for trace / span id according to the format used by Spring Cloud Sleuth. Adds also a few additional fields.

Installation

Via Composer

$ composer require upaid/elk

Publish the config

Run the following command to publish the package config file:

php artisan vendor:publish --provider="Upaid\Elk\Providers\ElkServiceProvider"

Add keys to .env

ELK_SERVICE_NAME='app name'
ELK_BANKNAME='bank name'
ELK_CHANNEL='channel for recognizing applications by logstash'

Or override config file

<?php

return [
    'logstash' => [
        'serviceName' => 'app name',
        'bankName' => 'bank name',
        'channel' => 'channel for recognizing applications by logstash',
        'showLogType' => true,
    ]
];

Changing default log fields and they order

To change default log fields or they order override fields property in config file

<?php

return [
    'logstash' => [
        'serviceName' => 'app name',
        'bankName' => 'bank name',
        'channel' => 'channel for recognizing applications by logstash',
        'fields' => [
            'timestamp',
            'severity' => 'level_name',
            'msg' => 'message',
            'span',
            'class' => 'class',
            'exception' => 'exception',
            'trace',
            'parent',
            'bank.name',
            'environment',
            'service',
            'channel',
            'context' => [
                'user.phone',
                'user.email',
                'card.id',
            ],
            'extra',
            'log_type',
        ],
        'showLogType' => true,
    ]
];

Hiding sensitive data

In order to remove sensitive data from the log file content you can add mask.fields property to the config file and specify the values of which fields should be hidden. Fields values will be replaced with mask.replacement property. It's also possible to hide values according to the patterns specified in mask.patterns. The example represents replacement of card number.

<?php

return [
    'mask' => [
        'replacement' => '[MASKED]',
        'fields' => [
            'password',
            'new_password',
            'password_confirmation',
            'card_no',
            'cvc',
        ],
        'patterns' => [
            '/^(?:4[0-9]{12}(?:[0-9]{3})?|[25][1-7][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$/',
        ],
    ]
];

Add logging channel

Add elk channel to the channels array in the config/logging.php config file as follows:

'channels' => [
    'elk' => [
        'driver' => 'custom',
        'via' => \Upaid\Elk\Services\Logging\CreateCustomLogger::class,
        'log_name' => 'global'
    ],
    
    ...

In the same file set default log channel to elk:

return [
    'default' => 'elk',
    
    ...

or when you want to use stack channel (default channel is 'stack') add elk to stack channel:

'channels' => [

    ...
    
    'stack' => [
        'driver' => 'stack',
        'channels' => ['elk'],
    ],

    ...

Usage

Standard logging in Laravel (to global.json)

Log::debug('An informational message.');

Logging to custom log file name (in this case to testlog.json):

use \Upaid\Elk\Services\Logging\Logger;

$logger = new Logger('testlog');
$logger->info('Hello World!');

Change log

Please see the changelog for more information on what has changed recently.

Security

If you discover any security related issues, please email author email instead of using the issue tracker.

统计信息

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

GitHub 信息

  • Stars: 14
  • Watchers: 3
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-10-10