ka4ivan/laravel-logger
最新稳定版本:3.0.1
Composer 安装命令:
composer require ka4ivan/laravel-logger
包简介
A Laravel package for advanced logging, providing structured logs, contextual information, and customizable log channels.
关键字:
README 文档
README
Laravel Logger 📦
A Laravel package for advanced logging, providing structured logs and tracking model changes
📖 Table of Contents
Installation
1️⃣ Require this package using Composer:
composer require ka4ivan/laravel-logger
2️⃣ Publish the package resources:
php artisan vendor:publish --provider="Ka4ivan\LaravelLogger\ServiceProvider"
This command publishes:
- Configuration file
- Views
3️⃣ Add a route to your web.php file:
Route::get('logs', [\Ka4ivan\LaravelLogger\Http\Controllers\LogViewerController::class, 'index'])->name('logs');
🔧 Default Configuration
Here’s the default config file for reference:
<?php return [ 'default' => env('LOG_CHANNEL', 'stack'), 'tracking' => [ 'default' => 'tracking', ], 'user' => [ 'fields' => ['id', 'email', 'name'], ], 'channels' => [ 'tracking' => [ 'driver' => 'daily', 'path' => storage_path('logs/_tracking.log'), 'level' => env('LOG_LEVEL', 'debug'), 'days' => 30, 'active' => env('LOGGING_ROUTES_ACTIVE', true), ], ], 'max_file_size' => 52428800, // 50MB 'pattern' => env('LOGGER_PATTERN', '*.log'), 'storage_path' => env('LOGGER_STORAGE_PATH', storage_path('logs')), ];
Usage
Logging
You can log anything using the package’s facade.
use Ka4ivan\LaravelLogger\Facades\Llog; // Example Llog::warning('Something happened', [ 'users' => User::count(), 'products' => Product::count(), 'variations' => Product::count(), 'orders' => Order::count(), 'leads' => Lead::count(), ]);
Or without a message:
use Ka4ivan\LaravelLogger\Facades\Llog; // Example Llog::channel('daily')->info([ 'first' => Brand::find('545e94e7-720f-4df6-9bef-bc0684f30690'), 'second' => Brand::find('16df9b24-52f3-4d39-9d96-ae24b6ad3a6a'), ]);
Logging Methods
All Laravel logging methods are available:
emergencyalertcriticalerrorwarningnoticeinfodebuglog
Tracking Model Changes
Preparing Your Model
Use the HasTracking trait to automatically track model changes (create, update, delete).
use Ka4ivan\LaravelLogger\Models\Traits\HasTracking; class Article extends Model { use HasTracking; }
It has the following structure:
Helpers
json_pretty
Formats a JSON string for better readability.
$data = Article::first(); $res = json_pretty($data);
License
This package is licensed under the MIT License. You can freely use, modify, and distribute this package as long as you include a copy of the license.
统计信息
- 总下载量: 397
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-16