How to Centralize Laravel Logs: A Complete Guide
Tutorials November 26, 2025 ยท 3 min read

How to Centralize Laravel Logs: A Complete Guide

Learn how to aggregate logs from multiple Laravel applications into a single dashboard for easier debugging and monitoring.

Managing logs across multiple Laravel applications can quickly become overwhelming. When an error occurs, you don't want to SSH into different servers or dig through individual log files. Centralized logging solves this by aggregating all your logs into a single, searchable dashboard.

Why Centralize Laravel Logs?

  • Single source of truth: All logs in one place
  • Faster debugging: Search across all applications instantly
  • Better visibility: Spot patterns across your infrastructure
  • Team collaboration: Everyone can access logs without server access
  • Retention management: Automatic log rotation and archival

Option 1: Using the 401 Clicks Laravel Package

The simplest way to centralize Laravel logs is using a purpose-built package. Here's how to set up 401 Clicks in under 5 minutes:

Step 1: Install the Package

composer require 401clicks/laravel-logger

Step 2: Add Environment Variables

# .env
CLICKS_API_TOKEN=your-api-token-here
CLICKS_API_URL=https://logs.401clicks.com/api/v1/logs

Step 3: Configure the Log Channel

Add the channel to your config/logging.php:

'channels' => [
    'clicks' => [
        'driver' => 'monolog',
        'handler' => \Clicks\Logger\ClicksLogHandler::class,
        'level' => env('LOG_LEVEL', 'debug'),
    ],

    'stack' => [
        'driver' => 'stack',
        'channels' => ['single', 'clicks'],
    ],
],

Step 4: Use the Stack Channel

Update your default log channel:

# .env
LOG_CHANNEL=stack

That's it! Your Laravel application now sends logs to 401 Clicks while keeping local logs for development.

Option 2: Custom HTTP Logger

If you prefer a DIY approach, you can create a custom Monolog handler:

<?php

namespace App\Logging;

use Monolog\Handler\AbstractProcessingHandler;
use Monolog\LogRecord;
use Illuminate\Support\Facades\Http;

class HttpLogHandler extends AbstractProcessingHandler
{
    protected function write(LogRecord $record): void
    {
        Http::withToken(config('logging.http.token'))
            ->post(config('logging.http.url'), [
                'level' => $record->level->name,
                'message' => $record->message,
                'context' => $record->context,
                'timestamp' => $record->datetime->format('c'),
            ]);
    }
}

Option 3: Syslog Forwarding

For server-level log aggregation, configure Laravel to use syslog and forward to your central server:

'syslog' => [
    'driver' => 'syslog',
    'level' => env('LOG_LEVEL', 'debug'),
    'facility' => LOG_USER,
],

Then configure your server's rsyslog or syslog-ng to forward logs.

Best Practices

1. Use Structured Logging

Log::info('User logged in', [
    'user_id' => $user->id,
    'ip_address' => request()->ip(),
    'user_agent' => request()->userAgent(),
]);

2. Set Appropriate Log Levels

# Production
LOG_LEVEL=warning

# Staging
LOG_LEVEL=info

# Development
LOG_LEVEL=debug

3. Include Request Context

Add a middleware to include request context in all logs:

Log::shareContext([
    'request_id' => request()->header('X-Request-ID', Str::uuid()),
    'url' => request()->fullUrl(),
]);

Conclusion

Centralized logging transforms how you debug Laravel applications. Whether you choose a managed service like 401 Clicks or build your own solution, the investment pays off quickly when you can search across all your applications from a single interface.

Start with one application, verify the setup works, then roll out to your entire infrastructure.

A

Admin

Published on November 26, 2025