forecho/laravel-trace-log 问题修复 & 功能扩展

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

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

forecho/laravel-trace-log

Composer 安装命令:

composer require forecho/laravel-trace-log

包简介

trace log for laravel

README 文档

README

Latest Stable Version Latest Unstable Version Total Downloads License

Install

composer require forecho/laravel-trace-log

if you use Lumen, you need add service provider to your bootstrap/app.php file.

$app->register(Forecho\LaravelTraceLog\TraceLogServiceProvider::class);

Configuration

This step is optional

php artisan vendor:publish --provider="Forecho\LaravelTraceLog\TraceLogServiceProvider"

if you use Lumen, you need add config file to your config directory.

cp vendor/forecho/laravel-trace-log/config/tracelog.php config/

and you need add code to your bootstrap/app.php file.

$app->configure('tracelog');

Note

  • The number of bits of the value corresponding to the key in log_filter_half_hide_keys must be greater than 2, otherwise all data is hidden.
  • If the configuration file causes an error, the filtering function will be invalid, the error message can be searched for request_params_filter_key_config_error to view the log.

additional_fields is an array of additional fields that will be added to the log. eg:

'additional_fields' => [
    'user_id' => [App\Models\User::class, 'getId'],
    'tag' => 'test', // value can use closure、string、array
  ],

add getId() method to User model, and the value of the field will be the return value of the method.

namespace App\Models;

class User 
{
    public static function getId(): ?int
    {
        return data_get(Auth::user(), 'id');
    }
}

Usage

Middleware(Optional)

change App\Http\Kernel.php file to add TraceLogMiddleware middleware.

use Forecho\LaravelTraceLog\Middleware\TraceLogMiddleware;

protected $middlewareGroups = [
    // ...

    'api' => [
        // ...        
        'request.tracelog'
    ],
];


protected $routeMiddleware = [
    // ...    
    'request.tracelog' => TraceLogMiddleware::class
];

Logging

use Forecho\LaravelTraceLog\TraceLog;

TraceLog::warning('This is a warning message.', ['foo' => 'bar']);
TraceLog::error('This is an error message.', ['foo' => 'bar']);
TraceLog::info('This is an info message.', ['foo' => 'bar']);
TraceLog::debug('This is a debug message.', ['foo' => 'bar']);

Get Trace ID

use Forecho\LaravelTraceLog\TraceLog;

TraceLog::getTraceId();

Curl Request

if you want next system use the same trace_id, you need add trace_id to your header

use Forecho\LaravelTraceLog\TraceLog;

$key = config('tracelog.trace_id_header_key');
$headers = [
  $key => TraceLog::getTraceId(),
]

forecho/laravel-trace-log 适用场景与选型建议

forecho/laravel-trace-log 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18.4k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2022 年 01 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 forecho/laravel-trace-log 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 forecho/laravel-trace-log 我们能提供哪些服务?
定制开发 / 二次开发

基于 forecho/laravel-trace-log 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-17