ka4ivan/laravel-logger

A Laravel package for advanced logging, providing structured logs, contextual information, and customizable log channels.

2.0.2 2025-08-18 19:06 UTC

This package is auto-updated.

Last update: 2025-08-18 19:08:20 UTC


README

License Build Status Latest Stable Version Total Downloads

Laravel Logger 📦

A Laravel package for advanced logging, providing structured logs and tracking model changes

image

📖 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"

3️⃣ Publish opcodesio/log-viewer (if this has not been done before):

php artisan log-viewer:publish

This command publishes:

  • Configuration file
  • Views

4️⃣ Add a route to your web.php file:

Route::get('logs', [\Ka4ivan\LaravelLogger\Http\Controllers\LogViewerController::class, 'index'])->name('logs');

Optionally, you can publish the configs for the opcodesio/log-viewer package.

php artisan vendor:publish --tag="log-viewer-config"

🔧 Default Configuration

Here’s the default config file for reference:

<?php

return [
    /*
     * Default log channel
     *
     * This defines the default logging channel to be used by the application.
     * The value is retrieved from the LOG_CHANNEL environment variable.
     */
    'default' => env('LOG_CHANNEL', 'stack'),

    /*
     * Tracking logs configuration
     */
    'tracking' => [
        /*
         * Defines the default logging channel for tracking events.
         */
        'default' => 'tracking',
    ],

    'user' => [
        /*
         * Specifies which fields from the authenticated user should be included in the logs.
         */
        'fields' => ['id', 'email', 'name'],
    ],

    /*
     * Log channels configuration
     *
     * Defines different logging channels with their respective settings.
     */
    'channels' => [
        /*
         * Tracking log channels
         */
        'tracking' => [
            'driver' => 'daily',
            'path' => storage_path('logs/_tracking.log'),
            'level' => env('LOG_LEVEL', 'debug'),
            'days' => 30,
            'active' => env('LOGGING_ROUTES_ACTIVE', true),
        ],
    ],
];

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(),  
]);  
image

Or without a message:

use Ka4ivan\LaravelLogger\Facades\Llog;  

// Example  
Llog::info([  
    'first' => Brand::find('545e94e7-720f-4df6-9bef-bc0684f30690'),  
    'second' => Brand::find('16df9b24-52f3-4d39-9d96-ae24b6ad3a6a'),  
]);  
image

Logging Methods

All Laravel logging methods are available:

  • emergency
  • alert
  • critical
  • error
  • warning
  • notice
  • info
  • debug
  • log

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:

image image image

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.