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.
Installs: 17
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Language:Blade
Requires
- php: >=7.4
- illuminate/contracts: >=5.0
Requires (Dev)
- driftingly/rector-laravel: ^2.0
- laravel/pint: ^1.14
- orchestra/testbench: ^8.22|^9.0
README
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 yourstorage/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
- Sidebar: Lists all available log files, sorted by modification date
- Main Panel: Displays log entries for the selected file
- Log Entries: Click to expand and view full messages and stack traces
- 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:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - 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 fileslogFileExists(string $filename): bool
- Check if log file existsgetLogFileContent(string $filename): string
- Get log file contentdeleteLogFile(string $filename): bool
- Delete a log file
LogParserService
parseLogFile(string $filename): Collection
- Parse log file into entriesparseLogContent(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
- Email: alanfaruq85@gmail.com
- GitHub: @mikailfaruqali
๐ 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! โญ