tomatophp/laravel-logstash
A Laravel package that adds a Logstash logging channel, letting you ship application logs to Logstash and the ELK stack with minimal configuration.
Install the package with Composer and it registers a logstash log channel for you — there is no service provider to publish or register manually:
composer require <vendor>/<package>:^2.0
Requirements are strict: PHP 8.2+, Laravel 12 or 13, and Monolog 3. If you're on an older Laravel or Monolog 2, stay on the v1 branch (composer require <vendor>/<package>:^1.0), which continues to receive the 1.x line.
The smallest working setup is:
.env:
LOGSTASH_HOST=logstash.internal:5000
config/logging.php — the package auto-registers the logstash channel, so you can reference it by name:
'stack' => [
'driver' => 'stack',
'channels' => ['single', 'logstash'],
],
The first use case to reach for is shipping application logs to Logstash → Elasticsearch/Kibana for centralized search, without changing any Log::info() calls in your code.
Add it to a stack, don't replace your local log. The most common pattern is keeping single/daily for local files and appending logstash to the stack, so you retain a local fallback if the pipeline is down.
Queued by default. Records go through a queued job, which keeps logging off the request path. This means:
LOGSTASH_QUEUE=false to send synchronously.Tune the channel per environment. The new v2 options (level, queue connection/name, timeout) let you configure the channel like any other Laravel log channel:
'logstash' => [
'driver' => 'logstash',
'host' => env('LOGSTASH_HOST'),
'level' => env('LOG_LEVEL', 'info'),
'queue' => env('LOGSTASH_QUEUE', true),
'connection'=> env('LOGSTASH_QUEUE_CONNECTION'), // dedicated connection
'queue_name'=> env('LOGSTASH_QUEUE_NAME', 'logs'),
'timeout' => 2,
],
Use a dedicated queue connection. If your Logstash job shares a connection with business jobs, a slow/backed-up queue delays shipping logs (and vice versa). Point the connection/queue_name options at a small, isolated queue so logging throughput is independent of application work.
Set the level threshold deliberately. Because the level option exists, you can send only warning+ to Logstash while keeping debug in local files — a clean way to control volume and cost in Elasticsearch.
Integration with existing logging: since it behaves like any Monolog-backed channel, contextual data, channels, and Log::withContext() all flow through unchanged — no wrapper or custom formatter required.
LOGSTASH_QUEUE=false.LOGSTASH_QUEUE=false, a hung Logstash endpoint can stall the request until the timeout fires. Keep timeout modest (1–3s).^1.0 on the v1 branch if you can't move yet.LOGSTASH_HOST is the only required env var, but host:port formatting varies by driver; confirm whether your setup expects a bare host:port or a URL and test one record end-to-end after configuring.config/logging.php and still get the driver — use this to bolt on custom level/queue/timeout combos rather than fighting the auto-registration.How can I help you explore Laravel packages today?