Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

View Logs Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

This package provides View Logs functionality, allowing developers to track and debug rendered Blade views in Laravel. To get started:

  1. Installation: Requires Laravel 8+ and PHP 8.0+. Install via Composer:
    composer require vendor/view-logs
    
  2. Publish Config: Publish the package's configuration file:
    php artisan vendor:publish --provider="Vendor\ViewLogs\ViewLogsServiceProvider"
    
  3. Enable Logging: Add the middleware to your app/Http/Kernel.php under $middleware:
    \Vendor\ViewLogs\Middleware\LogViews::class,
    
  4. First Use Case: After enabling, all Blade view renders will be logged to storage/logs/view-logs.log (configurable). Check the log file or use php artisan view:logs to inspect rendered views.

Implementation Patterns

Core Workflow

  • Middleware Integration: The package automatically logs view data (name, duration, timestamp, and rendered content) when Blade views are rendered.
  • Log Inspection: Use the view:logs Artisan command to display logs in a readable format:
    php artisan view:logs
    
  • Conditional Logging: Disable logging for specific views in config/view-logs.php:
    'exclude' => [
        'vendor.*',
        'auth.*',
    ],
    

Advanced Usage

  • Custom Log Channels: Override the default log channel in the config:
    'channel' => 'single',
    
  • Log Retention: Configure log retention (default: 30 days) to auto-prune old logs:
    'retention_days' => 30,
    
  • Programmatic Access: Retrieve logged views via the ViewLogs facade:
    use Vendor\ViewLogs\Facades\ViewLogs;
    
    $logs = ViewLogs::getLogs(); // Returns all logs
    $recentLogs = ViewLogs::getRecentLogs(5); // Last 5 logs
    

Integration Tips

  • Performance Impact: Logging rendered view content can impact performance. Use exclude patterns for non-critical views.
  • CI/CD Pipelines: Disable logging in production by setting the VIEW_LOGS_ENABLED environment variable to false.
  • Testing: Mock the middleware in tests to avoid cluttering logs:
    $this->app->instance(\Vendor\ViewLogs\Middleware\LogViews::class, new class {
        public function handle($request, \Closure $next) { return $next($request); }
    });
    

Gotchas and Tips

Pitfalls

  • Memory Usage: Logging rendered content (HTML) can consume significant memory for large views. Use exclude patterns for heavy templates.
  • Sensitive Data: Ensure no sensitive data (e.g., tokens, passwords) is accidentally logged. Use exclude or sanitize view data before rendering.
  • Log Rotation: If retention_days is set too low, critical logs may be purged unexpectedly. Monitor log file size.

Debugging

  • Missing Logs: Verify the middleware is registered in Kernel.php and the config is published.
  • Permission Issues: Ensure the storage/logs directory is writable:
    chmod -R 775 storage/logs
    
  • Artisan Command Errors: Clear cached views if logs aren’t updating:
    php artisan view:clear
    

Extension Points

  • 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)
    });
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle