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

Laravel Log Lens Laravel Package

rigits/laravel-log-lens

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package via Composer:

    composer require rigits/laravel-log-lens
    

    Publish the config (optional):

    php artisan vendor:publish --provider="Rigits\LogLens\LogLensServiceProvider"
    
  2. Basic Usage Inject the LogLens facade into a controller/service:

    use Rigits\LogLens\Facades\LogLens;
    
    public function someAction()
    {
        LogLens::info('User logged in', ['user_id' => 123]);
    }
    

    Logs will now appear in your configured channel (default: single channel).

  3. First Use Case Replace Log:: calls with LogLens:: for structured logging with automatic context (e.g., request IDs, user IDs).


Implementation Patterns

Structured Logging Workflow

  1. Contextual Logging Attach metadata (e.g., user, request) automatically:

    LogLens::withContext(['user_id' => auth()->id()])
           ->info('Order processed', ['order_id' => $order->id]);
    
  2. Middleware Integration Use middleware to inject request context:

    public function handle($request, Closure $next)
    {
        LogLens::withContext(['request_id' => $request->header('X-Request-ID')]);
        return $next($request);
    }
    
  3. Channel-Specific Logging Route logs to different channels (e.g., stack for production):

    LogLens::channel('stack')->error('Failed payment', ['amount' => 100]);
    
  4. Exception Handling Log exceptions with stack traces:

    try {
        // Risky code
    } catch (\Exception $e) {
        LogLens::error('Payment failed', ['exception' => $e]);
    }
    

Integration Tips

  • Monolog Integration: Works seamlessly with Laravel’s Monolog handler.
  • Queue Logs: Use LogLens::queue() to defer log processing.
  • Custom Processors: Extend LogLens to add pre-logging transformations (e.g., masking PII).

Gotchas and Tips

Pitfalls

  1. Context Leakage Avoid logging sensitive data (e.g., passwords) in contexts. Use LogLens::mask():

    LogLens::mask(['password' => '*****'])->info('Login attempt');
    
  2. Performance Overhead Excessive context attachment can slow down requests. Limit to essential metadata.

  3. Channel Misconfiguration Ensure the log-lens channel is properly defined in config/logging.php:

    'channels' => [
        'log-lens' => [
            'driver' => 'single',
            'path'   => storage_path('logs/laravel.log'),
        ],
    ],
    

Debugging

  • Log Levels: Use LogLens::debug(), LogLens::info(), etc., to filter logs in production.
  • Context Dumping: Check if contexts are attached via:
    LogLens::getContext(); // Returns current context array
    
  • Queue Issues: If logs don’t appear, verify the queue worker is running:
    php artisan queue:work
    

Extension Points

  1. Custom Context Providers Bind a service to inject dynamic context:

    LogLens::extendContext(function () {
        return ['tenant_id' => Tenant::current()->id];
    });
    
  2. Log Formatting Override the formatter via the LogLensServiceProvider:

    $this->app->singleton('log-lens.formatter', function () {
        return new CustomFormatter();
    });
    
  3. Event Listeners Listen for log events (e.g., LogLens\Events\LogEntryCreated):

    LogLens::listen(function ($entry) {
        // Post-process log entry
    });
    
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor