PHPackages                             frddl/laravel-simple-logging - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Logging &amp; Monitoring](/categories/logging)
4. /
5. frddl/laravel-simple-logging

ActiveLibrary[Logging &amp; Monitoring](/categories/logging)

frddl/laravel-simple-logging
============================

A simple, elegant logging package for Laravel with automatic method wrapping and beautiful web interface

v1.2.4(7mo ago)826MITPHPPHP ^8.0CI passing

Since Sep 13Pushed 7mo agoCompare

[ Source](https://github.com/frddl/laravel-simple-logging)[ Packagist](https://packagist.org/packages/frddl/laravel-simple-logging)[ RSS](/packages/frddl-laravel-simple-logging/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (8)Versions (11)Used By (0)

Laravel Simple Logging
======================

[](#laravel-simple-logging)

An elegant solution for monitoring your Laravel application's actual flow with comprehensive logging of warnings, infos, debug variables, and performance metrics. Features automatic method wrapping and a beautiful web interface for real-time application monitoring.

[![Latest Version on Packagist](https://camo.githubusercontent.com/1b60a2d381c0cccafe804e5dcb64227eaee8210f14b10d26629f2115b9cf74ce/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f667264646c2f6c61726176656c2d73696d706c652d6c6f6767696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/frddl/laravel-simple-logging)[![Total Downloads](https://camo.githubusercontent.com/b9f447beff91ae28a5e5ea048412bcd56eb9db98713bdedfaa27990092a4e622/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f667264646c2f6c61726176656c2d73696d706c652d6c6f6767696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/frddl/laravel-simple-logging)[![License](https://camo.githubusercontent.com/82c28809329dd8f558a73742a272b141d9205329316687d4d88edbb2116bab82/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f667264646c2f6c61726176656c2d73696d706c652d6c6f6767696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/frddl/laravel-simple-logging)[![Tests](https://github.com/frddl/laravel-simple-logging/workflows/Tests/badge.svg)](https://github.com/frddl/laravel-simple-logging/actions)[![Code Style](https://github.com/frddl/laravel-simple-logging/workflows/Code%20Style/badge.svg)](https://github.com/frddl/laravel-simple-logging/actions)[![PHP Version](https://camo.githubusercontent.com/2a1e36724d46ab08306cae76ede8d34f66d1e0355ca95c59acf83f885c67654c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f667264646c2f6c61726176656c2d73696d706c652d6c6f6767696e672e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/frddl/laravel-simple-logging)[![Laravel Version](https://camo.githubusercontent.com/9c20a5198355f8d9b78d00e3643d31ff115ba708385e4003916c8f4a297f7c1e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d382532422d7265642e7376673f7374796c653d666c61742d737175617265)](https://laravel.com)

[![image](https://private-user-images.githubusercontent.com/16150999/489199912-de8a4798-77f5-4b2b-8003-f51211d7bbb3.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzU0NTI0NjQsIm5iZiI6MTc3NTQ1MjE2NCwicGF0aCI6Ii8xNjE1MDk5OS80ODkxOTk5MTItZGU4YTQ3OTgtNzdmNS00YjJiLTgwMDMtZjUxMjExZDdiYmIzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDA2VDA1MDkyNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTBlOGJkMTA0NTMxYTllZTZiM2EyYjU2YTRhZjFhOTYwYWFiZmY2ZDJkYWRlMjQzMGRhOTNiMDU5ZmZmYTJkMGQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.Mj9Gffz2yJFCRkYKDugWu2BS7aV5tgt_Yj-TE4Bha0M)](https://private-user-images.githubusercontent.com/16150999/489199912-de8a4798-77f5-4b2b-8003-f51211d7bbb3.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzU0NTI0NjQsIm5iZiI6MTc3NTQ1MjE2NCwicGF0aCI6Ii8xNjE1MDk5OS80ODkxOTk5MTItZGU4YTQ3OTgtNzdmNS00YjJiLTgwMDMtZjUxMjExZDdiYmIzLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA0MDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNDA2VDA1MDkyNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTBlOGJkMTA0NTMxYTllZTZiM2EyYjU2YTRhZjFhOTYwYWFiZmY2ZDJkYWRlMjQzMGRhOTNiMDU5ZmZmYTJkMGQmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.Mj9Gffz2yJFCRkYKDugWu2BS7aV5tgt_Yj-TE4Bha0M)Features
--------

[](#features)

- 🎯 **Real-Time Application Flow Monitoring** - Track your app's actual execution flow with comprehensive logging
- ⚠️ **Smart Warning &amp; Info Logging** - Automatically capture warnings, infos, and debug variables throughout your application
- 🔍 **Advanced Debug Variable Tracking** - Monitor complex data structures, arrays, objects, and variables in real-time
- ✅ **Automatic Method Wrapping** - Wrap any method with start/end logging for complete flow visibility
- 🎨 **Beautiful Web Interface** - Modern, responsive log viewer with advanced filtering and search
- 🔗 **Request Tracing** - Group all logs by request ID for easy debugging and flow analysis
- 📊 **Performance Monitoring** - Automatic duration and memory usage tracking for optimization
- 🚨 **Intelligent Error Handling** - Automatic exception logging with detailed stack traces
- 🔒 **Sensitive Data Sanitization** - Automatically masks passwords, tokens, and sensitive information
- 💾 **Flexible Storage** - Store logs in database and/or files with configurable retention
- 🚀 **Zero Dependencies** - Works with any data structure and Laravel version
- 📱 **Mobile Responsive** - Beautiful interface on all devices for monitoring on-the-go

🎯 Perfect for Application Flow Monitoring
-----------------------------------------

[](#-perfect-for-application-flow-monitoring)

This package is specifically designed for **monitoring your Laravel application's actual execution flow**. It excels at:

- **🔍 Debug Variable Tracking** - Monitor complex data structures, arrays, objects, and variables as they flow through your application
- **⚠️ Warning &amp; Info Capture** - Automatically log warnings, infos, and debug messages with full context
- **📊 Real-Time Flow Analysis** - See exactly how your application processes requests, with timing and memory usage
- **🚨 Exception Tracking** - Capture and analyze errors with complete stack traces and variable states
- **🔗 Request Tracing** - Follow a single request through your entire application stack
- **📈 Performance Insights** - Identify bottlenecks and optimize your application based on real usage data

Perfect for debugging complex business logic, monitoring API responses, tracking user interactions, and understanding your application's behavior in production.

Installation
------------

[](#installation)

```
composer require frddl/laravel-simple-logging
```

Publish the config file and migrations:

```
php artisan vendor:publish --provider="Frddl\LaravelSimpleLogging\SimpleLoggingServiceProvider" --tag="config"
php artisan vendor:publish --provider="Frddl\LaravelSimpleLogging\SimpleLoggingServiceProvider" --tag="migrations"
```

Run the migrations:

```
php artisan migrate
```

Quick Start
-----------

[](#quick-start)

### 1. Add the trait to your controller:

[](#1-add-the-trait-to-your-controller)

```
use Frddl\LaravelSimpleLogging\Traits\SimpleLoggingTrait;

class YourController extends Controller
{
    use SimpleLoggingTrait;

    // Your methods here
}
```

### 2. Wrap your methods with automatic logging:

[](#2-wrap-your-methods-with-automatic-logging)

```
public function yourMethod(Request $request)
{
    return $this->logMethod('Your Method Name', $request->all(), function() use ($request) {
        // Your business logic here - automatic start/end logging!
        return response()->json(['message' => 'Success']);
    });
}
```

### 3. Add comprehensive monitoring with debug variables:

[](#3-add-comprehensive-monitoring-with-debug-variables)

```
public function processOrder(Request $request)
{
    return $this->logMethod('Process Order', $request->all(), function() use ($request) {
        // Monitor input data and validation
        $this->log('Order validation started', [
            'order_data' => $request->all(),
            'user_id' => $request->user_id,
            'items_count' => count($request->items ?? [])
        ], 'info');

        // Track business logic execution
        $order = Order::create($request->validated());
        $this->log('Order created successfully', [
            'order_id' => $order->id,
            'total_amount' => $order->total,
            'payment_method' => $order->payment_method
        ], 'info');

        // Monitor external API calls
        $payment = $this->processPayment($order);
        $this->log('Payment processed', [
            'payment_id' => $payment->id,
            'status' => $payment->status,
            'amount' => $payment->amount
        ], 'info');

        // Track warnings and potential issues
        if ($payment->amount !== $order->total) {
            $this->log('Payment amount mismatch detected', [
                'order_total' => $order->total,
                'payment_amount' => $payment->amount,
                'difference' => $payment->amount - $order->total
            ], 'warning');
        }

        return response()->json(['order' => $order]);
    });
}
```

Configuration
-------------

[](#configuration)

Edit `config/simple-logging.php`:

```
return [
    'enabled' => env('SIMPLE_LOGGING_ENABLED', true),
    'file_logging' => env('SIMPLE_LOGGING_FILE_LOGGING', false),
    'database_logging' => env('SIMPLE_LOGGING_DATABASE_LOGGING', true),
    'log_level' => env('SIMPLE_LOGGING_LEVEL', 'info'),
    'route_prefix' => 'logs',
    'middleware' => ['web'],
    'viewer' => [
        'per_page' => 50,
    ],
    'export' => [
        'max_records' => 100,
    ],
    'cleanup_old_logs_days' => env('SIMPLE_LOGGING_CLEANUP_DAYS', 30),
];
```

Log Cleanup &amp; Maintenance
-----------------------------

[](#log-cleanup--maintenance)

The package includes automatic log cleanup to prevent database bloat:

### Automatic Cleanup

[](#automatic-cleanup)

- **Scheduled Daily** - Runs automatically at 2:00 AM daily
- **Configurable Retention** - Keep logs for specified days (default: 30 days)
- **Background Processing** - Runs without blocking your application

### Manual Cleanup

[](#manual-cleanup)

```
# Clean up logs older than 30 days (uses config default)
php artisan simple-logging:cleanup

# Clean up logs older than 7 days
php artisan simple-logging:cleanup --days=7

# Clean up logs older than 90 days
php artisan simple-logging:cleanup --days=90
```

### Configuration

[](#configuration-1)

```
// In config/simple-logging.php
'cleanup_old_logs_days' => env('SIMPLE_LOGGING_CLEANUP_DAYS', 30),

// In your .env file
SIMPLE_LOGGING_CLEANUP_DAYS=30
```

### Disable Cleanup

[](#disable-cleanup)

Set the cleanup days to `null` or `0` to disable automatic cleanup:

```
'cleanup_old_logs_days' => null, // Disable cleanup
```

Usage
-----

[](#usage)

### Automatic Method Logging

[](#automatic-method-logging)

The `logMethod` function automatically logs:

- Method start with input data
- Method completion with duration and memory usage
- Any exceptions with stack traces

```
public function processOrder(Request $request)
{
        return $this->logMethod('Process Order', $request->all(), function() use ($request) {
        $order = Order::create($request->validated());

        $this->log('Order created', ['order_id' => $order->id], 'info');

        // Process payment
        $payment = $this->processPayment($order);

        $this->log('Payment processed', ['payment_id' => $payment->id], 'info');

        return response()->json(['order' => $order]);
    });
}
```

### Direct Logging for Application Flow Monitoring

[](#direct-logging-for-application-flow-monitoring)

Monitor your application's execution flow with detailed logging:

```
// Monitor user actions and debug variables
$this->log('User authentication started', [
    'email' => $request->email,
    'ip_address' => $request->ip(),
    'user_agent' => $request->userAgent(),
    'session_id' => session()->getId()
], 'info');

// Track business logic with complex data structures
$this->log('Order processing initiated', [
    'order_id' => $order->id,
    'customer_data' => $order->customer->toArray(),
    'items' => $order->items->map(function($item) {
        return [
            'name' => $item->name,
            'price' => $item->price,
            'quantity' => $item->quantity
        ];
    }),
    'total_calculation' => [
        'subtotal' => $order->subtotal,
        'tax' => $order->tax,
        'shipping' => $order->shipping,
        'total' => $order->total
    ]
], 'info');

// Monitor warnings and potential issues
$this->log('Low inventory warning', [
    'product_id' => $product->id,
    'current_stock' => $product->stock,
    'requested_quantity' => $quantity,
    'threshold' => $product->low_stock_threshold
], 'warning');

// Track errors with full context
$this->log('Payment processing failed', [
    'error' => $exception->getMessage(),
    'order_id' => $order->id,
    'payment_data' => $paymentData,
    'retry_count' => $retryCount,
    'stack_trace' => $exception->getTraceAsString()
], 'error');
```

### Log Levels

[](#log-levels)

- `emergency` - System is unusable
- `alert` - Action must be taken immediately
- `critical` - Critical conditions
- `error` - Error conditions
- `warning` - Warning conditions
- `notice` - Normal but significant conditions
- `info` - Informational messages (default)
- `debug` - Debug-level messages

Web Interface
-------------

[](#web-interface)

Access the log viewer at: `http://your-app.com/logs`

### Features:

[](#features-1)

- **Request Tracing** - See all logs grouped by request
- **Advanced Filtering** - Filter by level, date, search terms
- **Real-time Viewing** - Beautiful, responsive interface
- **Performance Metrics** - Duration and memory usage tracking
- **Mobile Friendly** - Works perfectly on all devices

Disable Logging
---------------

[](#disable-logging)

### Environment Variable (Recommended):

[](#environment-variable-recommended)

```
SIMPLE_LOGGING_ENABLED=false
```

### Or in code:

[](#or-in-code)

```
config(['simple-logging.enabled' => false]);
```

API Endpoints
-------------

[](#api-endpoints)

- `GET /logs` - Web interface
- `GET /logs/api` - JSON API for logs
- `GET /logs/api/statistics` - Log statistics
- `GET /logs/api/property-keys` - Available property keys

Sensitive Data Sanitization
---------------------------

[](#sensitive-data-sanitization)

The package automatically sanitizes sensitive data:

```
// This will be automatically masked
$this->log('User data', [
    'password' => 'secret123',           // → [HIDDEN]
    'token' => 'abc123xyz',              // → [HIDDEN]
    'authorization' => 'Bearer token123' // → Bearer [HIDDEN]
]);
```

Performance
-----------

[](#performance)

- **Minimal Overhead** - Only logs when enabled
- **Efficient Storage** - Optimized database queries
- **Memory Conscious** - Tracks memory usage
- **Configurable Cleanup** - Automatic old log removal

Examples
--------

[](#examples)

### Complete Controller Example

[](#complete-controller-example)

```
