cre8-it / log-relay
Monolog log channel that posts structured log data over HTTP
Requires
- php: ^8.3
- illuminate/http: ^12.0||^13.0
- illuminate/support: ^12.0||^13.0
- monolog/monolog: ^3.0
Requires (Dev)
- larastan/larastan: ^3.9
- laravel/pao: ^1.0
- laravel/pint: ^1.29
- orchestra/testbench: ^10.0||^11.0
- pestphp/pest: ^4.6||^5.0
- pestphp/pest-plugin-laravel: ^4.1||^5.0
- pestphp/pest-plugin-type-coverage: ^4.0||^5.0
- phpstan/extension-installer: ^1.4
README
Log Relay for Laravel
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_LEVEL', 'debug'), '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,datetimecontextandextra(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.
Set async to false (or sync) 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.