hasibkamal/view-logs
View your Laravel application logs in the browser with a simple /logs route. Install via Composer, register the service provider, optionally publish the views, and browse log files from your app without digging through storage manually.
This package provides View Logs functionality, allowing developers to track and debug rendered Blade views in Laravel. To get started:
composer require vendor/view-logs
php artisan vendor:publish --provider="Vendor\ViewLogs\ViewLogsServiceProvider"
app/Http/Kernel.php under $middleware:
\Vendor\ViewLogs\Middleware\LogViews::class,
storage/logs/view-logs.log (configurable). Check the log file or use php artisan view:logs to inspect rendered views.view:logs Artisan command to display logs in a readable format:
php artisan view:logs
config/view-logs.php:
'exclude' => [
'vendor.*',
'auth.*',
],
'channel' => 'single',
'retention_days' => 30,
ViewLogs facade:
use Vendor\ViewLogs\Facades\ViewLogs;
$logs = ViewLogs::getLogs(); // Returns all logs
$recentLogs = ViewLogs::getRecentLogs(5); // Last 5 logs
exclude patterns for non-critical views.VIEW_LOGS_ENABLED environment variable to false.$this->app->instance(\Vendor\ViewLogs\Middleware\LogViews::class, new class {
public function handle($request, \Closure $next) { return $next($request); }
});
exclude patterns for heavy templates.exclude or sanitize view data before rendering.retention_days is set too low, critical logs may be purged unexpectedly. Monitor log file size.Kernel.php and the config is published.storage/logs directory is writable:
chmod -R 775 storage/logs
php artisan view:clear
Custom Log Format: Extend the Vendor\ViewLogs\LogEntry class to add metadata (e.g., user ID, request IP):
namespace App\Extensions;
use Vendor\ViewLogs\LogEntry;
class ExtendedLogEntry extends LogEntry {
public function __construct($view, $duration, $content, $userId = null) {
parent::__construct($view, $duration, $content);
$this->userId = $userId;
}
}
Override the middleware to use your extended class.
Log Storage: Replace the default log storage by binding a custom Vendor\ViewLogs\LogRepository implementation:
$this->app->bind(\Vendor\ViewLogs\LogRepository::class, function () {
return new \App\Services\CustomLogRepository();
});
Event Listeners: Listen for view.logged events to react to logged views:
use Vendor\ViewLogs\Events\ViewLogged;
Event::listen(ViewLogged::class, function (ViewLogged $event) {
// Custom logic (e.g., notify Slack)
});
How can I help you explore Laravel packages today?