承接 mxnwire/laravel-logbarrel 相关项目开发

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

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

mxnwire/laravel-logbarrel

Composer 安装命令:

composer require mxnwire/laravel-logbarrel

包简介

Log every incoming HTTP request (and optionally its response) to a dedicated channel, with redaction and fine-grained options

README 文档

README

Log every incoming HTTP request — and optionally its response — to a dedicated channel, with sensitive-field redaction and fine-grained capture options. Drop it in and get a clean, queryable record of the traffic hitting your app.

Each request is written as a single log entry whose context holds the captured request and response data, for example:

{
    "method": "POST",
    "url": "https://app.test/login",
    "route": "login",
    "query": [],
    "body": { "email": "a@b.com", "password": "[REDACTED]" },
    "ip": "203.0.113.4",
    "user_agent": "Mozilla/5.0 ...",
    "user_id": 42,
    "user_email": "a@b.com",
    "status": 200,
    "duration_ms": 18.42
}

Installation

composer require mxnwire/laravel-logbarrel

The service provider is auto-discovered. By default the middleware is appended to the global HTTP stack, so every web/api request is logged with no further setup.

By default entries are written to a requests channel. Define it in config/logging.php (or set LOGBARREL_CHANNEL=stack/null to use your default):

'channels' => [
    'requests' => [
        'driver' => 'daily',
        'path' => storage_path('logs/requests.log'),
        'days' => 14,
    ],
],

Configuration

Publish the config to customise behaviour:

php artisan vendor:publish --tag=logbarrel-config

Key options in config/logbarrel.php:

  • enabled — master switch; when false the middleware passes requests through untouched (LOGBARREL_ENABLED).
  • register_global_middleware — when false, register manually with the logbarrel alias instead of the global stack.
  • channel / level / message — where, at what level and with what message each entry is logged. channel: null uses the default channel.
  • middleware_groups — only log requests whose matched route is in one of these groups (default web, api). Empty array logs everything, including unrouted requests.
  • except_paths — glob patterns (Str::is) whose paths are never logged (e.g. telescope*, _debugbar*).
  • request — toggle capture of method, url, route, query, body, headers, ip, user_agent, user.
  • response — toggle capture of status, duration, and (for JSON responses) content.
  • except_body / except_headers — keys/headers whose values are replaced with redacted (default [REDACTED]); body keys are matched recursively.
  • max_content_length — truncate captured bodies/response content beyond this many characters (null disables).
  • user_fields — fields captured for the authenticated user; each is a model attribute name or a callable receiving the user.

Per-request control

The LogBarrel facade lets you tailor — or switch off — logging for the current request from anywhere in the request lifecycle (a controller, form request, action, event listener…). Because the entry is written after the response is produced, anything you set is picked up when it matters. State is reset at the start of every request, so it never leaks to the next one.

use Mxnwire\LogBarrel\Facades\LogBarrel;

class CheckoutController
{
    public function store(Request $request)
    {
        // Don't log this request at all.
        LogBarrel::disable();

        // ...or force-log it even when globally off / outside the configured groups.
        LogBarrel::enable();

        // Attach extra context to the entry.
        LogBarrel::context(['order_id' => $order->id]);

        // Redact extra body keys on top of the configured list.
        LogBarrel::redact('ssn');                 // or ['ssn', 'card_number']

        // Capture only specific fields, or drop specific ones.
        LogBarrel::only('method', 'url', 'user'); // whitelist
        LogBarrel::without('body');               // blacklist

        // Send this request's entry to a different channel / message.
        LogBarrel::channel('audit')->message('checkout_completed');
    }
}

All methods are chainable and resolve the shared singleton, so LogBarrel::context([...])->redact('ssn')->channel('audit') works as expected.

Prefer a helper over the facade? logbarrel() returns the same singleton:

logbarrel()->disable();
logbarrel()->context(['order_id' => $order->id])->channel('audit');

Manual middleware registration

Set register_global_middleware to false, then apply the alias where needed:

Route::middleware('logbarrel')->group(function () {
    // ...
});

Testing

composer install
composer test

License

MIT.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固