定制 shipsaas/shipsaas-logger 二次开发

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

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

shipsaas/shipsaas-logger

Composer 安装命令:

composer require shipsaas/shipsaas-logger

包简介

Laravel ShipSaasLogger enables the tracing of requests across servers by marking each request with a unique ID. Skyrocket the production debugging.

README 文档

README

Build & Test (PHP 8.2) codecov

Laravel ShipSaasLogger enables the tracing of requests across servers by marking each request with a unique ID 🆔 for every log record of the given request.

Skyrocket your production debugging ⚒️.

Additionally, ShipSaasLogger solves the missing logs problem when you have a huge amount of traffic 😎. Making production logs more reliable and engineers won't have to scream "I can't find the logs" 🔥.

ShipSaaS Logger

Supports

  • Laravel 10+
  • PHP 8.2+

Installation

Install the library:

composer require shipsaas/shipsaas-logger

Usage

We ship a new Logger driver called shipsaas-logger which handles:

  • Create log file based on the requestId, e.g.: 7a559daf-f1fe-4a97-8eb8-40d0907c986b.log
  • Write request-based logs there
  • A fallback to the default log file, if requestId is not presented

Thus, it fixes the missing logs issue because we have independent log files and not yolo-write into 1 file (which will mess up the logs when having high traffic) 🚀

Nowadays, we can just tell Sumologic (or Cloudwatch, DataDog, etc.) to sync your log folder (a whole folder) 🔥. All your logs will be synced on the cloud.

Set up config/logging.php

Add a new channel called shipsaas-logger and change the configuration based on your needs

'shipsaas-logger' => [
    'driver' => 'shipsaas-logger',
    'path' => storage_path('logs/requests/laravel.log'), // can change to your desired path
    'default_log_file' => storage_path('logs/laravel.log'), // can change to your desired path
    'id-type' => 'ulid', // uuid, orderedUuid, ulid
    'use_json_format' => false, // set to true to write log as JSON
],

Update .env

Change the LOG_CHANNEL to shipsaas-logger

LOG_CHANNEL=shipsaas-logger

Play

Now that you have everything, hit some requests and try it out 😎.

class TransferController extends BaseController
{
    public function transfer(): JsonResponse
    {
        Log::info('begin transfer', [
            'amount' => ...,
            'recipient' => ...,
        ]); // this log will have uniqueRequestId
        
        // ...
        
        
        Log::info('transferred', [
            'amount' => ...,
            'recipient' => ...,
            'trasaction_id' => ...,
        ]); // this log will have uniqueRequestId
    }
}

And also congrats, no more "missing logs" pain for your app 😉.

Usage (Minimalism)

Inject Unique Request Id Logger Processor

By simply putting this piece of code into your AppServiceProvider:

// AppServiceProvider.php

use ShipSaasUniqueRequestLogger\UniqueRequestIdLoggerInitiator;

public function boot(): void
{
    $this->app->booted(fn () => UniqueRequestIdLoggerInitiator::init());
}

Play

Now that you have injected ShipSaaS Logger, hit some requests and try it out 😎.

Note: The Minimalism way only injects the UniqueRequestID generation into your application, it won't have any improvement for missing logs issue.

Testing

Run composer test 😆

Contributors

  • Seth Phat

Contributions & Support the Project

Feel free to submit any PR, please follow PSR-1/PSR-12 coding conventions and testing is a must.

If this package is helpful, please give it a ⭐️⭐️⭐️. Thank you!

License

MIT License

shipsaas/shipsaas-logger 适用场景与选型建议

shipsaas/shipsaas-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 59 次下载、GitHub Stars 达 14, 最近一次更新时间为 2023 年 10 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 shipsaas/shipsaas-logger 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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