yuriitatur/laravel-logger-boost
Composer 安装命令:
composer require yuriitatur/laravel-logger-boost
包简介
A simple package for boosting your logging experience in Laravel
README 文档
README
Laravel logger boost
Add useful processors to your app.
Installation
composer require yuriitatur/laravel-logger-boost
Testing
composer test
Usage
Disclaimer
This package is designed to work with a Laravel framework, but it can be used with/without any framework as the set of useful Monolog processors.
Laravel
Add BoostLogger to your channel config in config/logging.php
'channels' => [
'single' => [
'driver' => 'single',
'tap' => [\YuriiTatur\MonologHandler\BoostLogger::class],
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
],
],
Or you can add even more context with AddMoreContext
'channels' => [
'single' => [
'driver' => 'single',
'tap' => [
\YuriiTatur\MonologHandler\BoostLogger::class,
\YuriiTatur\MonologHandler\AddMoreContext::class
],
'path' => storage_path('logs/laravel.log'),
'level' => env('LOG_LEVEL', 'debug'),
],
],
This will add multiple extra fields like hostname, is_cli, route or user. Thus, returning all that data in each
record is overhead. So make use of a stack driver with bubble option
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => [ // this is our main channels
'single-error', // single-error channel will not bubble message to single
'single',
],
'ignore_exceptions' => false,
],
'single' => [ // all debug+ messages goes with only BoostLogger
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'debug',
'formatter' => JsonFormatter::class,
'tap' => [
BoostLogger::class,
BufferRecords::class . ':10', // optionally enable record buffering, with specified buffer size
],
],
'single-error' => [ // if something happens, use AddMoreContext and bubble => false
'driver' => 'single',
'path' => storage_path('logs/laravel.log'),
'level' => 'error',
'bubble' => false, // if this is true, the message will be duplicated
'formatter' => JsonFormatter::class,
'tap' => [
BoostLogger::class,
AddMoreContext::class,
],
],
}
Eloquent
You can also add log key to your eloquent models, to keep track of all that happened to them with one key.
First, add log_key column to your table;
# in your migration
Schema::table('my_models', function (Blueprint $table) {
$table->string('log_key')->nullable()->unique();
});
The reason, why it's not in a separate thing called AddLogKeyColumn class/method is because, requirements to
this column may vary. Create your own how you like it.
Next, add LogKeyAwareTrait trait in your model. You can use overtakeLogs and applyLogKey methods now.
# in your model
class Product extends Model
{
use LogKeyAwareTrait;
}
# in your service
public function createProduct($params)
{
$product = new Product($params);
$product->applyLogKey(); # creating event is a good place to put this
$product->save();
}
public function updateProduct($id, $params)
{
$product = Product::findOrFail($id);
$product->overtakeLogs(); # this will take log key from the model and apply to your logger
$product->update($params);
}
Queue Jobs
This package automatically registers new LoggerAwareWorkerDecorator queue worker.
That now resets all processors between each job, this is done specifically to reload log keys, so each
job can be traced using its own id.
License
This code is under MIT license, read more in the LICENSE file.
yuriitatur/laravel-logger-boost 适用场景与选型建议
yuriitatur/laravel-logger-boost 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 yuriitatur/laravel-logger-boost 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yuriitatur/laravel-logger-boost 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 1
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-27