定制 bit-mx/saloon-logger-plug-in 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

bit-mx/saloon-logger-plug-in

Composer 安装命令:

composer require bit-mx/saloon-logger-plug-in

包简介

README 文档

README

A Laravel plug-in for the Saloon HTTP client Saloon v4 that provides automatic observability and traceability for all HTTP interactions made with the Saloon library.

This package transparently logs requests, responses and exceptions to the database, and links all events using a single trace_id (ULID).

Features

  • Traceability: Generates a unique identifier to tie the request, response and any exception together.
  • Transparent integration: Enable logging simply by applying traits to the connector and request classes.
  • Data sanitization: Automatically censors sensitive fields (for example passwords or authentication tokens) in logged payloads and headers.
  • Reliable storage: Uses a dedicated database table for structured storage of logs.

Installation

Requirements

{
  "php": "^8.2",
  "laravel/framework": "^12.39",
  "saloonphp/saloon": "^4.0"
}

Install via Composer

Install the package using Composer:

composer require bit-mx/saloon-logger-plug-in

Publish and run migrations

This command will publish the migration into your database/migrations directory:

php artisan vendor:publish --tag=saloon-logger-migrations

Then run the migrations:

php artisan migrate

Publish configuration (optional)

You can publish the configuration file to customize which fields are censored:

php artisan vendor:publish --tag=saloon-logger-config

This will create config/saloon-logger.php.

Usage

Step 1: Apply the Traits

To enable traceability, add the HasLogging trait to your connector and the ProvidesDefaultBody trait to your request.

Connector example:

use BitMx\SaloonLoggerPlugIn\Traits\HasLogging;
use Saloon\Http\Connector;

class ExampleConnector extends Connector
{
    use HasLogging;

    public function resolveBaseUrl(): string
    {
        return 'https://example.com';
    }
}

Request example:

use BitMx\SaloonLoggerPlugIn\Traits\ProvidesDefaultBody;
use BitMx\SaloonLoggerPlugIn\Contracts\HasDefaultBody;
use Saloon\Enums\Method;
use Saloon\Http\Request;

class ExampleRequest extends Request  implements HasDefaultBody
{
    use ProvidesDefaultBody;

    public function __construct(
        public string $id,
    ) {}

    protected Method $method = Method::GET;

    public function resolveEndpoint(): string
    {
        return '/test';
    }

    protected function defaultBody(): array
    {
        return [
            'id' => $this->id,
        ];
    }
}

Step 2: Send the Request

Whenever a request is sent through this connector, the package will automatically log the events to the database table.

$connector = new ExampleConnector;
$request = new ExampleRequest($id);
$connector->send($request);

If an HTTP or network exception occurs (for example a 500), the package will log the request and the exception.

Other languages

Spanish

Custom sanitizers

If you need a custom way to sanitize payloads or headers before they are stored, implement the SanitizerRequestContract and register your class in the package configuration under the sanitizers.request array.

Example request custom sanitizer:

namespace App\Sanitizers;

use BitMx\SaloonLoggerPlugIn\Contracts\SanitizerRequestContract;

class MyRequestSanitizer implements SanitizerRequestContract
{
    public static function sanitize(mixed $data): mixed
    {
        // perform your custom sanitization here
        return $data;
    }
}

If you need a custom way to sanitize the response before they are stored, implement the SanitizerResponseContract and register your class in the package configuration under the sanitizers.response array.

Example Response custom sanitizer:

namespace App\Sanitizers;

use BitMx\SaloonLoggerPlugIn\Contracts\SanitizerResponseContract;
use Saloon\Http\Response;

class MyResponseSanitizer implements SanitizerResponseContract
{
    public static function sanitize(Response $data): mixed
    {
        // perform your custom sanitization here
        return $data;
    }
}

Then register it in config/saloon-logger.php:

'sanitizers' => [
        'request' => [
            \BitMx\SaloonLoggerPlugIn\Sanitizers\Request\JsonSanitizerRequest::class,
            \App\Sanitizers\MyRequestSanitizer::class,
        ],
        'response' => [
            \BitMx\SaloonLoggerPlugIn\Sanitizers\Response\JsonSanitizerResponse::class,
            \App\Sanitizers\MyResponseSanitizer::class,
        ],
    ],

Sanitizers are applied in the order they appear in the configuration. Each sanitizer receives the data and must return the updated value.

Prune & Backup

You can configure the package to prune old records and make a backup of the records. The options are available separately in the configuration file

bit-mx/saloon-logger-plug-in 适用场景与选型建议

bit-mx/saloon-logger-plug-in 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 138 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「logging」 「api」 「laravel」 「tracer」 「saloon」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 bit-mx/saloon-logger-plug-in 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-03