mathewparet/laravel-global-log-context 问题修复 & 功能扩展

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

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

mathewparet/laravel-global-log-context

最新稳定版本:v1.0.1

Composer 安装命令:

composer require mathewparet/laravel-global-log-context

包简介

Adds global logging context

README 文档

README

Easily add extra logging context to all logs

Installation

Install the library

composer require mathewparet/laravel-global-log-context

Create a context definition class

// app/tools/LogContext/LogContext.php
use mathewparet\LaravelGlobalLogContext\Contracts\ContextDefinition;

namespace App\Tools\LogContext;

class LogContext implements ContextDefinition
{
    public static function context(): array
    {
        return [
            'user' => request()?->user()?->email,
            'ip' => requiest()?->ip()
        ];
    }
}

Bind this in your service provider

// app/providers/AppServiceProvider.php
namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use mathewparet\LaravelGlobalLogContext\Contracts\ContextDefinition;
use App\Tools\LogContext\LogContext;

class AppServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->bind(ContextDefinition::class, LogContext::class);
    }
}

Update logger config

// config/logging.php
// ...
use mathewparet\LaravelGlobalLogContext\ExtraLoggingContext\AddExtraContextToLogs;

return [
    // ...
    'channels' => [
        'stack' => [
            'driver' => 'stack',
            // ....
            'tap' => AddExtraContextToLogs::class
        ]
    ]
];

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-07