laravel-logger maintained by ka4ivan
Description
A Laravel package for advanced logging, providing structured logs, contextual information, and customizable log channels.
Authors
Last update
2025/12/18 16:45
(dev-main)
License
Downloads
509
Tags
log - logging - debugging - logger - monitoring - laravel - error-tracking - log-management - model-changes - model-tracking
A Laravel package for advanced logging, providing structured logs and tracking model changes
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.