iqbalatma / laravel-log-center-channel
Laravel log channel that ships logs to a centralized log management system via M2M API
Package info
github.com/iqbalatma/laravel-log-center-channel
pkg:composer/iqbalatma/laravel-log-center-channel
1.0.0
2026-07-15 18:36 UTC
Requires
- php: ^8.2
README
A custom Laravel/Monolog log channel that ships log records to a centralized log management system over its M2M API.
How it works
- A global middleware (
AssignRequestId) generates a UUIDrequest_idper HTTP request and shares it as log context. - The
log_centerchannel formats each record into a structured payload (capturing the authenticated actor, IP, endpoint, method andrequest_idsynchronously, while the request is still alive). - The payload is dispatched to the queue (
SendLogToCenterJob) and POSTed to{base_url}/api/m2m/logswithX-Client-Id/X-Client-Secretheaders. - Any failure is written to the configured
fallback_channelinstead of recursing.
Install (local path package)
composer.json:
"repositories": [ { "type": "path", "url": "packages/iqbalatma/laravel-log-center-channel" } ]
composer require iqbalatma/laravel-log-center-channel:@dev php artisan vendor:publish --tag=log-center-config
Configure
Add the channel in config/logging.php:
'log_center' => [ 'driver' => 'custom', 'via' => \Iqbalatma\LaravelLogCenterChannel\Logger::class, 'level' => \Psr\Log\LogLevel::ERROR, ],
Enable it, e.g. LOG_STACK=single,log_center in .env.
Environment
LOG_CENTER_BASE_URL=https://logs.example.com LOG_CENTER_CLIENT_ID=your-client-id LOG_CENTER_CLIENT_SECRET=your-client-secret LOG_CENTER_APP_NAME=ng-hris LOG_CENTER_NODE_ID= # defaults to hostname LOG_CENTER_ENVIRONMENT= # defaults to APP_ENV (config('app.env')) LOG_CENTER_TIMEOUT=5 LOG_CENTER_TRIES=3 LOG_CENTER_QUEUE_CONNECTION=redis LOG_CENTER_QUEUE=default LOG_CENTER_FALLBACK_CHANNEL=single
Payload
client_id, id, created_at, updated_at are set by the log center itself.
The channel sends:
| Field | Source |
|---|---|
message |
log message |
level |
lowercased Monolog level |
trace |
context.exception trace, if present |
actor_id |
auth()->id() or guest |
actor_email |
authenticated user email (nullable) |
app_name |
LOG_CENTER_APP_NAME |
node_id |
LOG_CENTER_NODE_ID / hostname |
environment |
LOG_CENTER_ENVIRONMENT / config('app.env') |
ip_address |
client IP (null in console) |
endpoint |
request URI (null in console) |
http_method |
request method (null in console) |
request_id |
per-request UUID |
logged_at |
record timestamp (ISO-8601) |