mikailfaruqali/log-viewer

A modern, elegant, and feature-rich log viewer for Laravel applications. Experience a beautiful glassmorphism-inspired interface that makes viewing and managing your application logs both intuitive and visually appealing.

2.2.0 2025-09-11 22:30 UTC

This package is auto-updated.

Last update: 2025-09-11 22:30:42 UTC


README

License: MIT PHP Version Laravel

A modern, elegant, and feature-rich log viewer for Laravel applications. Experience a beautiful glassmorphism-inspired interface that makes viewing and managing your application logs both intuitive and visually appealing.

โœจ Features

๐ŸŽจ Modern UI/UX

  • Glassmorphism Design: Beautiful translucent interface with backdrop blur effects
  • Dark Theme: Eye-friendly dark interface perfect for development environments
  • Responsive Layout: Fully responsive design that works on desktop, tablet, and mobile
  • Smooth Animations: CSS transitions and hover effects for enhanced user experience
  • Mobile-First: Collapsible sidebar and touch-friendly interactions on mobile devices

๐Ÿ“ File Management

  • Smart File Detection: Automatically discovers all .log files in your storage/logs directory
  • File Switching: Seamlessly switch between different log files with a single click
  • File Deletion: Safely delete old log files directly from the interface with confirmation
  • File Sorting: Log files are automatically sorted by modification time (newest first)
  • File Status: Visual indicators for active/selected files

๐Ÿ“Š Log Parsing & Display

  • Intelligent Parsing: Advanced regex-based log parsing that handles Laravel's log format
  • Multi-line Support: Properly handles stack traces and multi-line log entries
  • Log Levels: Color-coded log levels (debug, info, notice, warning, error, critical, alert, emergency)
  • Timestamp Formatting: Human-readable timestamp display
  • Environment Detection: Automatically detects and displays the environment (production, local, etc.)

๐Ÿ” Enhanced Viewing Experience

  • Expandable Entries: Click to expand log entries and view full messages and stack traces
  • Stack Trace Viewer: Properly formatted stack trace display for debugging
  • Message Truncation: Long messages are truncated with ellipsis and expandable on demand
  • Empty State Handling: Graceful handling of empty log files and missing selections
  • Error Recovery: Robust error handling for corrupted or unreadable log files

๐Ÿ” Security & Access Control

  • Authentication Required: Protected by Laravel's authentication middleware by default
  • Configurable Middleware: Easily add custom authorization middleware
  • CSRF Protection: All delete operations are CSRF protected
  • Input Validation: Comprehensive validation for all user inputs
  • Safe File Operations: Prevents directory traversal and unauthorized file access

โšก Performance & Reliability

  • Efficient Parsing: Optimized log parsing algorithm that handles large files
  • Memory Management: Processes logs efficiently without excessive memory usage
  • Error Logging: Internal errors are logged for debugging purposes
  • Graceful Degradation: Continues working even when individual log files have issues

๐Ÿ› ๏ธ Developer Experience

  • Zero Dependencies: No external CSS or JS frameworks required
  • Easy Installation: Simple Composer installation with auto-discovery
  • Configurable Routes: Customize the route path and middleware
  • Publishable Views: Customize the interface to match your application's design
  • Clean Architecture: Well-structured codebase following Laravel conventions

๐Ÿš€ Installation

Install the package via Composer:

composer require mikailfaruqali/log-viewer

The package uses Laravel's auto-discovery feature, so no additional setup is required.

โš™๏ธ Configuration

Basic Configuration

The package works out-of-the-box, but you can publish the configuration file for customization:

php artisan vendor:publish --provider="Snawbar\LogViewer\LogViewerServiceProvider" --tag="config"

This creates a config/snawbar-log-viewer.php file:

<?php

return [
    /*
    |--------------------------------------------------------------------------
    | Log Viewer Route Path
    |--------------------------------------------------------------------------
    | This is the URI path where the log viewer will be accessible.
    | Default: 'logs' (accessible at /logs)
    |
    */
    'route-path' => 'logs',

    /*
    |--------------------------------------------------------------------------
    | Log Viewer Route Middleware
    |--------------------------------------------------------------------------
    | These middleware will be assigned to every route in the package.
    | You can add your own middleware here to restrict access.
    | Default: ['web', 'auth'] - requires authentication
    |
    */
    'middleware' => ['web', 'auth'],
];

Advanced Configuration

Custom Route Path:

'route-path' => 'admin/logs', // Accessible at /admin/logs

Custom Middleware:

'middleware' => ['web', 'auth', 'admin'], // Add admin middleware

Role-based Access:

'middleware' => ['web', 'auth', 'can:view-logs'], // Laravel Gates/Policies

View Customization

Publish the views to customize the interface:

php artisan vendor:publish --provider="Snawbar\LogViewer\LogViewerServiceProvider" --tag="views"

This publishes views to resources/views/vendor/snawbar-log-viewer/ for customization.

๐Ÿ“– Usage

Accessing the Log Viewer

After installation, navigate to the configured route:

https://your-app.com/logs

Note: You must be authenticated to access the log viewer (default middleware: ['web', 'auth'])

Interface Overview

  1. Sidebar: Lists all available log files, sorted by modification date
  2. Main Panel: Displays log entries for the selected file
  3. Log Entries: Click to expand and view full messages and stack traces
  4. Delete Button: Remove old log files (with confirmation)

Log Entry Features

Each log entry displays:

  • Log Level: Color-coded badges (debug, info, warning, error, etc.)
  • Timestamp: When the log entry was created
  • Environment: Application environment (production, local, staging, etc.)
  • Message: The log message (truncated with expand option)
  • Stack Trace: Full error details and stack trace (when available)

Mobile Experience

The interface is fully responsive:

  • Collapsible sidebar on mobile devices
  • Touch-friendly interactions
  • Optimized layout for smaller screens
  • Swipe gestures and mobile navigation

๐ŸŽจ Screenshots

Desktop View

The main interface showing log files in the sidebar and expanded log entries:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ [โ˜ฐ] Log Viewer Dashboard                                    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ ๐Ÿ“ Log Files        โ”‚ ๐Ÿ“‹ Viewing: laravel-2024-01-15.log   โ”‚
โ”‚                     โ”‚                                       โ”‚
โ”‚ laravel-2024-01-15  โ”‚ [ERROR] 2024-01-15 10:30:45         โ”‚
โ”‚ laravel-2024-01-14  โ”‚ Undefined variable: user             โ”‚
โ”‚ laravel-2024-01-13  โ”‚ โ–ผ Click to expand stack trace        โ”‚
โ”‚                     โ”‚                                       โ”‚
โ”‚ [๐Ÿ—‘๏ธ] Delete buttons โ”‚ [INFO] 2024-01-15 10:25:12          โ”‚
โ”‚                     โ”‚ User login successful                 โ”‚
โ”‚                     โ”‚                                       โ”‚
โ”‚                     โ”‚ [WARNING] 2024-01-15 09:15:33        โ”‚
โ”‚                     โ”‚ Deprecated function usage            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ”ง Advanced Usage

Custom Middleware

Create custom middleware for role-based access:

// app/Http/Middleware/LogViewerAccess.php
<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;

class LogViewerAccess
{
    public function handle(Request $request, Closure $next)
    {
        if (!auth()->user()->hasRole('admin')) {
            abort(403, 'Access denied to log viewer');
        }

        return $next($request);
    }
}

Register and use the middleware:

// config/snawbar-log-viewer.php
'middleware' => ['web', 'auth', App\Http\Middleware\LogViewerAccess::class],

Integration with Laravel Gates

Use Laravel's authorization gates:

// app/Providers/AuthServiceProvider.php
Gate::define('view-logs', function ($user) {
    return $user->hasPermission('view-logs');
});
// config/snawbar-log-viewer.php
'middleware' => ['web', 'auth', 'can:view-logs'],

Environment-Specific Configuration

Configure different access rules per environment:

// config/snawbar-log-viewer.php
'middleware' => app()->environment('production') 
    ? ['web', 'auth', 'admin'] 
    : ['web'],

๐Ÿงช Log Format Support

The package supports Laravel's default log format and handles:

  • Standard Laravel Logs: [timestamp] environment.LEVEL: message
  • Stack Traces: Multi-line error details and backtraces
  • Context Data: Additional context information in log entries
  • Custom Formats: Extensible parsing for custom log formats

Supported Log Levels

Level Color Description
๐Ÿ” DEBUG Gray Detailed debug information
โ„น๏ธ INFO Blue General information messages
โ„น๏ธ NOTICE Blue Normal but significant events
โš ๏ธ WARNING Yellow Warning messages
โŒ ERROR Red Error conditions
๐Ÿšจ CRITICAL Dark Red Critical conditions
๐Ÿšจ ALERT Dark Red Action must be taken immediately
๐Ÿ†˜ EMERGENCY Purple System is unusable

๐Ÿ›ก๏ธ Security Considerations

Production Environment

For production use, implement strict access controls:

// Recommended production middleware
'middleware' => [
    'web', 
    'auth', 
    'role:admin',           // Role-based access
    'throttle:60,1',        // Rate limiting
    'verified',             // Email verification
],

IP Restriction

Add IP-based restrictions:

// In a custom middleware
public function handle($request, Closure $next)
{
    $allowedIps = ['192.168.1.100', '10.0.0.50'];
    
    if (!in_array($request->ip(), $allowedIps)) {
        abort(403);
    }
    
    return $next($request);
}

Audit Logging

Log access to the log viewer:

// In your middleware
Log::info('Log viewer accessed', [
    'user' => auth()->user()->email,
    'ip' => $request->ip(),
    'user_agent' => $request->userAgent(),
]);

๐Ÿ› Troubleshooting

Common Issues

1. "No log files found"

  • Ensure logs exist in storage/logs/
  • Check file permissions (Laravel must be able to read the directory)
  • Verify the log files have .log extension

2. "Access denied" or 403 errors

  • Check authentication status
  • Verify middleware configuration
  • Ensure user has required permissions

3. Empty or garbled log entries

  • Check log file format compatibility
  • Ensure files are not corrupted
  • Verify character encoding (UTF-8)

4. Performance issues with large log files

  • Consider log rotation
  • Archive old log files
  • Use Laravel's log rotation features

Debug Mode

Enable debug logging for troubleshooting:

// In your .env file
LOG_LEVEL=debug

// This will log parsing errors and other debug information

๐Ÿ”„ Log Rotation & Maintenance

Automatic Cleanup

Set up automatic log cleanup:

// In a scheduled command
$this->command('log:clear --days=30'); // Keep 30 days of logs

File Size Management

Monitor and manage large log files:

# Check log file sizes
du -sh storage/logs/*

# Compress old logs
gzip storage/logs/laravel-2024-01-*.log

๐Ÿค Contributing

We welcome contributions! Please see our contributing guidelines:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Setup

# Clone the repository
git clone https://github.com/mikailfaruqali/log-viewer.git

# Install dependencies
composer install

# Run tests
./vendor/bin/phpunit

๐Ÿ“š API Reference

Services

LogFileService

  • getLogFiles(): Collection - Get all available log files
  • logFileExists(string $filename): bool - Check if log file exists
  • getLogFileContent(string $filename): string - Get log file content
  • deleteLogFile(string $filename): bool - Delete a log file

LogParserService

  • parseLogFile(string $filename): Collection - Parse log file into entries
  • parseLogContent(string $content): Collection - Parse log content

LogEntry (Data Object)

  • $timestamp - Log entry timestamp
  • $environment - Application environment
  • $level - Log level (debug, info, warning, error, etc.)
  • $message - Log message
  • $extra - Additional data (stack traces, context)

Routes

Method URI Action Description
GET /logs LogViewerController@index Display log viewer interface
DELETE /logs/delete LogViewerController@delete Delete a log file

๐Ÿ“„ License

This package is open-sourced software licensed under the MIT License.

MIT License

Copyright (c) 2024 Mikail Faruq Ali

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

๐Ÿ‘จโ€๐Ÿ’ป Author

Mikail Faruq Ali

๐Ÿ™ Acknowledgments

  • Laravel community for the amazing framework
  • Bootstrap Icons for the beautiful icons
  • All contributors who help improve this package

โญ If you find this package useful, please give it a star on GitHub! โญ