moktech/mocklogger-sdk
Composer 安装命令:
composer require moktech/mocklogger-sdk
包简介
Mocklogger SDK is a Laravel package designed to facilitate effortless integration with the Mocklogger logging tool for developers.
关键字:
README 文档
README
MockLogger SDK offers functionality for logging request and response data of a Laravel application. This SDK provides methods to capture and log data pertaining to incoming HTTP requests and their associated responses.
With the MockLogger SDK, you can easily capture and log data from HTTP requests and responses, helping you monitor and analyze your application's interactions with external services and users actions.
Installation
To get started with the MockLogger SDK, follow these installation steps:
Install the SDK:
Install the MockLogger SDK using Composer:
composer require moktech/mocklogger-sdk
Publish Configuration:
Publish the MockLogger SDK configuration file using Artisan:
php artisan vendor:publish --tag=mocklogger-config
Register Service Provider:
Open the config/app.php file and add the service provider to the providers array:
'providers' => [ // ... Moktech\MockLoggerSDK\MockloggerServiceProvider::class, ],
Set Environment Variables:
Set the following environment variables in your application's .env. You can obtain these values from your Mocklogger application:
MOCKLOGGER_HOST_URL=http://localhost:8000 MOCKLOGGER_APP_ID="My Application" MOCKLOGGER_APP_KEY=c3ce75317d9c876d209a9f439b345345 MOCKLOGGER_APP_API_TOKEN=EomxCzUG0HFukdRWgKL26ThXuRstFTW
Usage
Once you have installed the MockLogger SDK and configured your environment, you can now use it to log request and response data. Here are two ways to use the SDK:
Method 1: Using sendLog
Use this in your Terminable Middleware (Sunctum protected URL).
use Moktech\MockLoggerSDK\MockLogger; class TerminableMiddleware { protected $logger; public function __construct(MockLogger $logger) { $this->logger = $logger; } public function handle(Request $request, Closure $next): Response { return $next($request); } public function terminate(Request $request, Response $response) { try { $this->logger->sendLog($request, $response); } catch (\Throwable $th) { Log::info($th->getMessage()); } } }
Method 2: Using sendData
You can also manually assemble the request and response data and use the sendData method to log it.
use Moktech\MockLoggerSDK\MockLogger; $data = [ "request" => [ 'user' => [ 'name' => 'Kevin Muchwat', 'email' => 'kevinmuchwat@gmail.com', ], 'ip_address' => $request->ip(), 'full_url' => $request->fullUrl(), 'route_name' => $request->route()->getName(), 'method' => $request->method(), 'payload' => $request->all(), 'agent' => $request->userAgent(), ], "response" => [ 'status_code' => $response->getStatusCode(), 'content' => $response->getContent(), 'format' => $response->headers->get('content-type'), 'location' => $response->headers->get('location'), ], ]; $logger = new MockLogger(); $logger->sendData($data);
Server Health Monitoring
MockLogger SDK empowers you to maintain optimal server performance by allowing you to set usage limits on CPU, memory, and hard disk space. If any of these limits are exceeded, the SDK automatically sends a detailed log to administrator's email configured in config/mocklogger.php.
return [ ... // Configure server health monitor. 'monitor' => [ // Specify the web server service running, e.g., 'nginx' or 'apache2'. 'server_service' => 'nginx', // Set email configuarations, default is 4 emails per 30mins interval. 'email' => [ // Set time interval to get emails (minutes), default is 30 minutes 'interval' => 30, // Set number of emails to be sent in an interval, default is 4 emails. 'count' => 4, ], // Configure thresholds for resources. 'thresholds' => [ // Set the CPU usage threshold (percentage). 'cpu_usage' => env('MOCKLOGGER_CPU_THRESHOLD', 90), // Set the memory usage threshold (percentage). 'memory_usage' => env('MOCKLOGGER_MEMORY_THRESHOLD', 80), // Set the hard disk drive usage threshold (percentage). 'hard_disk_space' => env('MOCKLOGGER_HDD_THRESHOLD', 80), ], ], ]
To start monitoring your server, run this command:
php artisan mocklogger:monitor
For continuous monitoring, you can schedule this command with a cron job. Keep your server in check effortlessly with this tool.
moktech/mocklogger-sdk 适用场景与选型建议
moktech/mocklogger-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 137 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 09 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「logging」 「http」 「debugging」 「middleware」 「requests」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 moktech/mocklogger-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 moktech/mocklogger-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 moktech/mocklogger-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
A PHP package that takes a snapshot of your application and allows you to retrieve it later to help with debugging.
A Zend Framework module that sets up Monolog for logging in applications.
Laravel Database Query Logger and debug helper.
Asynchronous Sentry for Symfony - Fire and forget
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
统计信息
- 总下载量: 137
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-21