Search by

cre8-it / log-relay

cre8-it

Monolog log channel that posts structured log data over HTTP

Package info

github.com/cre8-it/log-relay

pkg:composer/cre8-it/log-relay

Statistics

Installs: 382

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 3

v0.1.2 2026-11-26 09:20 UTC

This package is auto-updated.

Last update: 2026-11-30 05:20:07 UTC


README

Log Relay for Laravel

Packagist PHP from Packagist Laravel versions GitHub Workflow Status (main) Total Downloads

Minimal Monolog log channel that posts structured log data over HTTP.

Installation

You can install the package via Composer:

composer require cre8-it/log-relay

Register the channel in config/logging.php:

use LogRelay\LogRelay\HttpHandler;

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

    'http' => [
        'driver' => 'monolog',
        'handler' => HttpHandler::class,
        'level' => env('LOG_RELAY_LEVEL', 'warning'),
        'handler_with' => [
            'url' => env('LOG_RELAY_URL', ''),
            'token' => env('LOG_RELAY_TOKEN', ''),
            'app' => env('LOG_RELAY_APP', ''),
            'async' => true,
        ],
    ],
],

Then set the connection values in your .env file:

LOG_RELAY_URL=
LOG_RELAY_TOKEN=
LOG_RELAY_APP=

app is sent with each record so the ingress can tell sources apart. If you omit it, the handler falls back to config('app.name').

Usage

Write logs as usual. Messages that reach the http channel are posted as JSON:

use Illuminate\Support\Facades\Log;

Log::error('Payment failed', ['order' => 42]);
Log::channel('http')->info('Invoice created');

Each request includes:

  • app, message, level, channel, datetime
  • context and extra (normalized so exceptions and objects are JSON-safe)
  • Authorization: Bearer {token} when a token is configured

Sync and async

async defaults to true. The HTTP call is deferred with Laravel's defer() helper and runs after the request or command has been handled, including failed requests.

If an HTTP request uses a legacy Laravel kernel without Illuminate\Foundation\Http\Middleware\InvokeDeferredCallbacks in its global middleware, or skips middleware entirely, the sender posts inline instead. It writes one notice per handler per request to PHP's error log. Add \Illuminate\Foundation\Http\Middleware\InvokeDeferredCallbacks::class to the legacy kernel's global $middleware array to restore deferred HTTP delivery. Artisan commands and queue jobs do not need this middleware.

Deferred delivery still occupies the application worker. Each record is a separate POST with a 1-second timeout by default (override handler_with.timeout in seconds). There is no retry or delivery guarantee. Keep a local channel first in the stack and redact sensitive fields before forwarding; a local line formatter does not change the JSON payload.

A connection failure, timeout, HTTP 401/403/429, or 5xx stops further POSTs from that handler for the current Laravel request/job scope. The next scope tries again. A bad record (for example HTTP 413 or 422) drops only its remote copy. The first delivery failure per handler and scope writes a diagnostic to PHP's error log, without tokens, response bodies, or record contents.

Set async to false to send immediately:

'async' => false,

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Thank you for considering contributing to Log Relay for Laravel! Please review our contributing guide to get started.

Credits

License

Log Relay for Laravel is open-sourced software licensed under the MIT license.