halilcosdu/laravel-logweaver
Composer 安装命令:
composer require halilcosdu/laravel-logweaver
包简介
Laravel S3-compatible log system.
README 文档
README
Laravel LogWeaver
Laravel LogWeaver is a PHP package designed to provide a simple and flexible way to log events in your Laravel application. It offers a fluent interface for creating logs, allowing you to easily specify the log level, resource, content, and storage disk.
Features
- Fluent Interface: Easily create logs with a fluent, chainable interface.
- Multiple Log Levels: Supports different log levels including 'info', 'warning', 'error', and 'critical'.
- Resource Specification: Specify the resource of the log, such as 'system' or 'event'.
- Customizable Storage: Choose your storage disk and directory.
- Parameter Validation: Ensures the validity of log parameters before logging.
- Array and JSON Conversion: Convert your logs to array or JSON format.
- Asynchronous Logging: Log events asynchronously with optional waiting for the log to be written to the disk.
Installation
You can install the package via composer:
composer require halilcosdu/laravel-logweaver
composer require league/flysystem-aws-s3-v3 "^3.0" --with-all-dependencies composer require league/flysystem-ftp "^3.0" composer require league/flysystem-sftp-v3 "^3.0"
AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_DEFAULT_REGION=us-east-1 AWS_BUCKET= AWS_USE_PATH_STYLE_ENDPOINT=false
You can publish the config file with:
php artisan vendor:publish --tag="logweaver-config"
This is the contents of the published config file:
return [ 'sleep' => env('LOG_WEAVER_SLEEP', 0.5), ];
Usage
\HalilCosdu\LogWeaver\Facades\LogWeaver::description(string $description): static \HalilCosdu\LogWeaver\Facades\LogWeaver::logResource(string $logResource): static \HalilCosdu\LogWeaver\Facades\LogWeaver::level(string $level): static \HalilCosdu\LogWeaver\Facades\LogWeaver::content(array $content): static \HalilCosdu\LogWeaver\Facades\LogWeaver::disk(string $disk): static \HalilCosdu\LogWeaver\Facades\LogWeaver::directory(string $directory): static \HalilCosdu\LogWeaver\Facades\LogWeaver::relation(?array $relation): static \HalilCosdu\LogWeaver\Facades\LogWeaver::log(?string $path = null, bool $wait = false): array \HalilCosdu\LogWeaver\Facades\LogWeaver::download(string $path, $name = null, array $headers = []): StreamedResponse \HalilCosdu\LogWeaver\Facades\LogWeaver::delete(string|array $paths): bool \HalilCosdu\LogWeaver\Facades\LogWeaver::validation(?bool $validation): static \HalilCosdu\LogWeaver\Facades\LogWeaver::get(string $path): string \HalilCosdu\LogWeaver\Facades\LogWeaver::toArray(): array \HalilCosdu\LogWeaver\Facades\LogWeaver::toJson($options = 0): false|string
$log = LogWeaver::description('User logged in') ->logResource('event') ->content(['email' => 'test@example.com']) ->level('info') ->relation(['user_id' => 1]) ->toArray();
$log = LogWeaver::description('System error occurred') ->logResource('system') ->content(['error' => 'Database connection failed']) ->level('error') ->log($path, $wait);
$log = LogWeaver::description('Payment gateway down') ->logResource('event') ->content(['gateway' => 'Stripe', 'status' => 'down']) ->level('critical') ->log();
$log = LogWeaver::description('Disk space running low') ->logResource('system') ->content(['disk_space' => '10% remaining']) ->level('warning') ->toJson();
$log = LogWeaver::description('User registered') ->logResource('event') ->content(['user_id' => 2, 'email' => 'newuser@example.com']) ->level('info') ->disk('local') ->directory('custom_logs') ->log();
If you want to disable built-in validation, you can use the following methods:
Built-in validations are:
$rules = [ 'level' => ['required', 'in:info,warning,error,critical'], 'log_resource' => ['required', 'in:system,event'], 'description' => ['required', 'string'], 'directory' => ['string'], 'disk' => ['string', 'in:s3,local,ftp,sftp,public'], 'content' => ['required', 'array'], ];
$log = LogWeaver::description('User registered') ->validation(false) ->logResource('custom_input') ->content(['user_id' => 2, 'email' => 'newuser@example.com']) ->level('custom_input') ->disk('custom_input') ->directory('custom_logs') ->log();
$response = LogWeaver::download(string $path, $name = null, array $headers = []): StreamedResponse; $response = LogWeaver::delete(string|array $paths): bool; $response = LogWeaver::get(string $path): string;
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
halilcosdu/laravel-logweaver 适用场景与选型建议
halilcosdu/laravel-logweaver 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.65k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2024 年 04 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「HalilCosdu」 「laravel-logweaver」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 halilcosdu/laravel-logweaver 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 halilcosdu/laravel-logweaver 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 halilcosdu/laravel-logweaver 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel SignalWire - Send Fax From Laravel
Laravel Ollama API Wrapper - Interact with the Ollama API
Alfabank REST API integration
Laravel Fine tuner is a package designed for the Laravel framework that automates the fine-tuning of OpenAI models. It simplifies the process of adjusting model parameters to optimize performance, tailored specifically for Laravel applications. This tool is ideal for developers looking to enhance AI
Laravel package for Accurate Online API integration.
Laravel AI Chatbot Package
统计信息
- 总下载量: 1.65k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-04-16