falahatiali/laravel-advance-log-monitoring

๐Ÿฆ… Simorgh Logger - Advanced log monitoring package for Laravel with dashboard, alerts, and intelligent categorization. Named after the legendary Persian bird.

Installs: 5

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/falahatiali/laravel-advance-log-monitoring

v1.0.2 2025-10-07 15:15 UTC

This package is auto-updated.

Last update: 2025-11-12 15:23:05 UTC


README

Simorgh Logger

๐Ÿฆ… Simorgh Logger for Laravel

Latest Version on Packagist Total Downloads MIT Licensed GitHub Repository

๐Ÿฆ… Simorgh Logger - A powerful and feature-rich logging package for Laravel applications with dashboard, alerts, and intelligent categorization. Named after the legendary Persian bird that watches over and protects all under its wings.

"Just as the mythical Simorgh watches over all birds under its wings, this package watches over and protects all your application logs."

โœจ Features

  • ๐ŸŽฏ Smart Categorization - Organize logs by modules (auth, api, payments, etc.)
  • ๐Ÿ“Š Visual Dashboard - Beautiful web interface with real-time updates
  • ๐Ÿšจ Automated Alerts - Email, Slack, Telegram notifications with intelligent triggers
  • ๐Ÿ” Advanced Filtering - Search and filter logs with powerful query builder
  • ๐Ÿ“ˆ Analytics & Stats - Comprehensive statistics and performance metrics
  • ๐Ÿ”’ Security - Automatic sanitization of sensitive data
  • ๐Ÿ“ Multiple Storage - Database, File, Sentry, Elasticsearch support
  • ๐ŸŽจ Export Options - JSON, CSV, XML export capabilities
  • โšก Performance - Queue support and optimized queries
  • ๐Ÿงน Auto Cleanup - Configurable retention policies

๐ŸŽฎ Try Live Demo

Want to see Simorgh Logger in action before installing? Try our demo!

Quick Demo (One Command)

git clone https://github.com/falahatiali/laravel-advance-log-monitoring.git
cd laravel-advance-log-monitoring
chmod +x demo.sh && ./demo.sh

Then visit: http://localhost:8000/logs

Docker Demo (No PHP Required)

git clone https://github.com/falahatiali/laravel-advance-log-monitoring.git
cd laravel-advance-log-monitoring
docker-compose up -d

Visit: http://localhost:8080/logs

๐Ÿ“– Full demo guide: DEMO.md

๐Ÿ“ฆ Installation

Composer

composer require falahatiali/simorgh-logger

Laravel Auto-Discovery

The package will automatically register itself. If auto-discovery is disabled, add the service provider to your config/app.php:

'providers' => [
    // ...
    Simorgh\Logger\SimorghLoggerServiceProvider::class,
],

Publish Configuration

php artisan vendor:publish --provider="Simorgh\Logger\SimorghLoggerServiceProvider" --tag="simorgh-logger-config"

Publish Migrations

php artisan vendor:publish --provider="Simorgh\Logger\SimorghLoggerServiceProvider" --tag="simorgh-logger-migrations"

Run Migrations

php artisan migrate

๐Ÿš€ Quick Start

Basic Usage

use Simorgh\Logger\Facades\Simorgh;

// Simple logging
Simorgh::info('Application started successfully');

// With context
Simorgh::error('Payment failed', [
    'user_id' => 123,
    'amount' => 99.99,
    'payment_method' => 'credit_card'
]);

// Categorized logging
Simorgh::category('auth')
    ->warning('Failed login attempt', [
        'email' => 'user@example.com',
        'ip' => request()->ip()
    ]);

Advanced Usage

// Chainable methods
Simorgh::category('api')
    ->user(auth()->id())
    ->context(['request_id' => Str::uuid()])
    ->error('API rate limit exceeded', [
        'endpoint' => '/api/users',
        'limit' => 100,
        'current' => 150
    ]);

// Performance logging
Simorgh::performance('Database query', 0.250, [
    'query' => 'SELECT * FROM users WHERE...',
    'rows' => 1500
]);

// Security events
Simorgh::security('Suspicious activity detected', [
    'type' => 'multiple_failed_logins',
    'ip' => request()->ip(),
    'user_agent' => request()->userAgent()
]);

// Exception logging
try {
    // Some risky operation
} catch (\Exception $e) {
    Simorgh::exception($e, [
        'context' => 'Payment processing',
        'user_id' => auth()->id()
    ]);
}

๐Ÿ“Š Dashboard

Access the dashboard at /simorgh-logger (or your configured prefix).

Features:

  • Real-time log monitoring
  • Advanced filtering and search
  • Log statistics and charts
  • Alert management
  • Export functionality
  • Settings configuration

Dashboard Routes:

  • /simorgh-logger - Main dashboard
  • /simorgh-logger/logs - Log browser
  • /simorgh-logger/stats - Statistics
  • /simorgh-logger/alerts - Alert management
  • /simorgh-logger/settings - Configuration

๐Ÿ“ธ Dashboard Screenshots

Main Dashboard

Main Dashboard Real-time overview with statistics, log distribution charts, and recent log entries

All Logs Browser

All Logs Advanced filtering, search capabilities, and export options (JSON, CSV, XML)

Statistics & Analytics

Statistics Comprehensive insights with date range filters, distribution charts, and trend analysis

Alert Configuration

Alerts Configure alert channels (Email, Slack, Telegram) and threshold settings

๐Ÿšจ Alerts Configuration

Email Alerts

// config/simorgh-logger.php
'alerts' => [
    'enabled' => true,
    'channels' => [
        'email' => [
            'enabled' => true,
            'to' => 'admin@example.com',
            'subject_prefix' => '[Simorgh Alert]',
        ],
    ],
    'thresholds' => [
        'critical' => [
            'count' => 5,
            'time_window' => '1 hour',
        ],
    ],
],

Slack Alerts

'alerts' => [
    'channels' => [
        'slack' => [
            'enabled' => true,
            'webhook' => 'https://hooks.slack.com/services/...',
            'channel' => '#alerts',
        ],
    ],
],

Telegram Alerts

'alerts' => [
    'channels' => [
        'telegram' => [
            'enabled' => true,
            'bot_token' => '123456789:ABCdefGHIjklMNOpqrsTUVwxyz',
            'chat_id' => '-123456789',
        ],
    ],
],

๐Ÿ”ง Configuration

Environment Variables

# Enable/disable Simorgh Logger
SIMORGH_LOGGER_ENABLED=true

# Storage driver (database, file, sentry, elasticsearch)
LOG_STORAGE_DRIVER=database

# Alert settings
LOG_ALERTS_ENABLED=true
LOG_ALERT_EMAIL_ENABLED=true
LOG_ALERT_EMAIL_TO=admin@example.com
LOG_ALERT_SLACK_ENABLED=true
LOG_ALERT_SLACK_WEBHOOK=https://hooks.slack.com/services/...

# Dashboard settings
LOG_DASHBOARD_ENABLED=true
LOG_DASHBOARD_PREFIX=advanced-logger
LOG_DASHBOARD_REALTIME=true

# Auto-logging
LOG_AUTO_REQUESTS=true
LOG_AUTO_MODELS=false
LOG_AUTO_QUERIES=false

# Performance
LOG_USE_QUEUE=false
LOG_RETENTION_ENABLED=true
LOG_RETENTION_DAYS=30

Custom Route Prefix & Middleware

You can customize the route prefix and middleware for the dashboard:

Option 1: Using Environment Variables

# Custom route prefix (default: advanced-logger)
LOG_DASHBOARD_PREFIX=admin/dashboard/logs/panel

Option 2: Using Config File

// config/advanced-logger.php
'dashboard' => [
    'enabled' => true,
    'prefix' => 'admin/dashboard/logs/panel', // Custom prefix
    'middleware' => ['web', 'auth', 'role:admin'], // Add your middleware
    // ...
],

Examples:

Configuration Resulting URL
prefix => 'advanced-logger' mysite.com/advanced-logger
prefix => 'admin/logs' mysite.com/admin/logs
prefix => 'admin/dashboard/logs/panel' mysite.com/admin/dashboard/logs/panel

Middleware Examples:

// Basic authentication only
'middleware' => ['web', 'auth'],

// With role-based access (Spatie Permission)
'middleware' => ['web', 'auth', 'role:admin'],

// With permission-based access
'middleware' => ['web', 'auth', 'permission:view-logs'],

// Multiple roles
'middleware' => ['web', 'auth', 'role:admin|developer'],

// Custom middleware
'middleware' => ['web', 'auth', 'custom.admin'],

Auto-Logging Middleware

Add to your app/Http/Kernel.php:

protected $middleware = [
    // ...
    \Simorgh\Logger\Middleware\LogRequestsMiddleware::class,
];

๐Ÿ“ˆ Statistics & Analytics

// Get comprehensive stats
$stats = Simorgh::getStats();

// Get stats with filters
$stats = Simorgh::getStats([
    'level' => ['error', 'critical'],
    'date_from' => '2025-01-01',
    'date_to' => '2025-01-31'
]);

// Get logs with pagination
$logs = Simorgh::getLogs([
    'category' => 'auth',
    'search' => 'login'
], 50);

๐Ÿ“ค Export & Cleanup

Export Logs

// Export as JSON
$json = Simorgh::exportLogs(['level' => 'error'], 'json');

// Export as CSV
$csv = Simorgh::exportLogs(['category' => 'auth'], 'csv');

// Export as XML
$xml = Simorgh::exportLogs(['date_from' => '2025-01-01'], 'xml');

Cleanup Commands

The package includes a powerful cleanup command that automatically removes old logs:

# Cleanup logs older than 30 days (uses config default)
php artisan logs:cleanup

# Cleanup logs older than specific number of days
php artisan logs:cleanup --days=30

# Cleanup only specific level
php artisan logs:cleanup --level=error

# Cleanup only specific category
php artisan logs:cleanup --category=auth

# Dry run (see what would be deleted without actually deleting)
php artisan logs:cleanup --dry-run

# Compress logs before deletion (saves backup)
php artisan logs:cleanup --compress

Automatic Cleanup (Cron Job)

The cleanup command runs automatically! No manual setup needed. ๐ŸŽ‰

By default, it runs daily at 2 AM and removes logs older than:

  • 7 days in local environment
  • 14 days in staging environment
  • 30 days in production environment

Customize the schedule:

# .env
LOG_RETENTION_ENABLED=true
LOG_RETENTION_DAYS=30  # Not used by auto-scheduler, but by manual command
// config/advanced-logger.php
'retention' => [
    'enabled' => true,
    'days' => [
        'local' => 7,
        'staging' => 14,
        'production' => 30,  // Delete logs older than 30 days
    ],
    'compress_before_delete' => true,
    'cleanup_schedule' => '0 2 * * *', // Daily at 2 AM (cron expression)
],

Custom cron schedules:

Expression Description
0 2 * * * Daily at 2:00 AM (default)
0 0 * * 0 Weekly on Sunday at midnight
0 3 * * 1 Every Monday at 3:00 AM
*/30 * * * * Every 30 minutes
0 */6 * * * Every 6 hours

Important: Make sure Laravel's scheduler is running:

# Add to your crontab (crontab -e)
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

Manual Cleanup

You can also run cleanup manually at any time:

# Clean up now using environment defaults
php artisan logs:cleanup

# Force cleanup of logs older than 1 month
php artisan logs:cleanup --days=30

# Test what would be deleted first
php artisan logs:cleanup --days=30 --dry-run

๐Ÿ”’ Security Features

Automatic Sanitization

The package automatically sanitizes sensitive data:

// These will be automatically masked
Simorgh::info('User data', [
    'password' => 'secret123',        // โ†’ '[REDACTED]'
    'api_token' => 'abc123',         // โ†’ '[REDACTED]'
    'credit_card' => '4111111111111111', // โ†’ '[REDACTED]'
    'ssn' => '123-45-6789',          // โ†’ '[REDACTED]'
]);

Custom Sanitization Patterns

// config/simorgh-logger.php
'security' => [
    'sensitive_patterns' => [
        '/password/i',
        '/token/i',
        '/secret/i',
        '/key/i',
        '/credit_card/i',
        '/ssn/i',
        '/social_security/i',
        '/my_custom_field/i',  // Add your own patterns
    ],
    'mask_replacement' => '[REDACTED]',
],

๐ŸŽฏ Categories

Predefined categories for better organization:

  • auth - Authentication & Authorization
  • api - API Requests & Responses
  • payments - Payment Processing
  • database - Database Operations
  • mail - Email Operations
  • queue - Queue Processing
  • cache - Cache Operations
  • file - File Operations
  • security - Security Events
  • performance - Performance Monitoring
  • debug - Debug Information

๐Ÿ”Œ Integrations

Sentry Integration

'integrations' => [
    'sentry' => [
        'enabled' => true,
        'dsn' => env('SENTRY_LARAVEL_DSN'),
    ],
],

Elasticsearch Integration

'integrations' => [
    'elasticsearch' => [
        'enabled' => true,
        'host' => env('ELASTICSEARCH_HOST', 'localhost:9200'),
        'index' => env('ELASTICSEARCH_LOG_INDEX', 'laravel-logs'),
    ],
],

๐Ÿงช Testing

# Run tests
composer test

# Run with coverage
composer test-coverage

Testing in Your Application

// Test logging
Simorgh::shouldReceive('error')->once()->with('Test message', []);
Simorgh::error('Test message', []);

// Test alerts
$alertHandler = app(\Simorgh\Logger\Handlers\AlertHandler::class);
$results = $alertHandler->testChannels();

๐Ÿ“ Changelog

Please see CHANGELOG for more information on what has changed recently.

๐Ÿค Contributing

Please see CONTRIBUTING for details.

๐Ÿ› Bug Reports

If you discover a security vulnerability, please send an email to falaahatiali@gmail.com. All security vulnerabilities will be promptly addressed.

๐Ÿ“„ License

The MIT License (MIT). Please see License File for more information.

๐Ÿ™ Credits

๐Ÿ“š Additional Resources

Made with โค๏ธ and ๐Ÿฆ… for the Laravel community

"Just as the mythical Simorgh watches over all birds under its wings, this package watches over and protects all your application logs."