tailstream-io / laravel-logger
A beautiful Laravel log driver package with performance monitoring, request tracking, and cache-based batching
Requires
- php: ^8.3
- illuminate/cache: ^12.0
- illuminate/http: ^12.0
- illuminate/log: ^12.0
- illuminate/support: ^12.0
- monolog/monolog: ^3.0
Requires (Dev)
- laravel/pint: ^1.25
- mockery/mockery: ^1.6
- orchestra/testbench: ^10.0
- pestphp/pest: ^4.0
- phpunit/phpunit: ^12.0
README
A beautiful Laravel log driver package with performance monitoring, request tracking, and cache-based batching capabilities. Built with Laravel 12+ compatibility and following convention over configuration principles.
About Tailstream
Tailstream is a modern log aggregation and monitoring platform designed for developers who need powerful observability without the complexity. It provides real-time log streaming, intelligent alerting, and beautiful dashboards to help you monitor your applications effectively.
โจ Features
- ๐ Minimal Configuration - Works with just basic setup
- โก Performance Monitoring - Track response times and memory usage
- ๐ Request Correlation - UUID-based request tracking across your application
- ๐ฆ Smart Batching - Cache-based log batching with configurable thresholds
- ๐ Queue Support - Optional asynchronous processing via Laravel queues
- ๐ฏ Tailstream Integration - Direct integration with Tailstream API
- ๐ก๏ธ Laravel 12 Native - Built using Laravel 12's modern patterns and conventions
- ๐งช Comprehensive Tests - Full Pest test suite with 100% coverage
๐ Installation
composer require tailstream-io/laravel-logger
Configure Stream Credentials
Add your stream credentials to your .env
file:
TAILSTREAM_STREAM_UUID=your-stream-uuid TAILSTREAM_STREAM_SECRET=your-stream-secret
That's it! The package will automatically:
- Register itself via Laravel's package discovery
- Add global middleware to track all requests
- Start sending request data to Tailstream immediately
๐ Quick Start
Your application is now automatically sending request data to Tailstream! All HTTP requests will be tracked and batched for efficient delivery.
โ๏ธ Configuration
While the package requires minimal configuration to get started, you can customize it further:
php artisan vendor:publish --tag=tailstream-logger-config
Environment Variables
# Basic Settings TAILSTREAM_ENABLED=true TAILSTREAM_BASE_URL=https://app.tailstream.io/api TAILSTREAM_SAMPLING_RATE=1.0 TAILSTREAM_INSTANCE_ID=web-01 # Batching Configuration TAILSTREAM_BATCH_SIZE=50 # Flush when batch reaches this size TAILSTREAM_FLUSH_FREQUENCY=10 # Flush every N requests TAILSTREAM_CACHE_TTL=3600 # Queue Configuration (Optional) TAILSTREAM_USE_QUEUE=false # Enable asynchronous processing TAILSTREAM_QUEUE_NAME=tailstream # Queue name for processing TAILSTREAM_QUEUE_CONNECTION= # Queue connection (default: app default) # Middleware TAILSTREAM_AUTO_MIDDLEWARE=true
๐ What Gets Logged
Data is sent in batches to the Tailstream ingest endpoint (https://app.tailstream.io/api/ingest/{stream_uuid}
) with Bearer token authentication using NDJSON format:
{"ts":"2024-03-15T10:30:45.123456+00:00","host":"web-01","path":"/api/users","method":"GET","status":200,"rt":0.245,"bytes":1024,"src":"192.168.1.100"}
{"ts":"2024-03-15T10:31:12.789012+00:00","host":"web-01","path":"/api/posts","method":"POST","status":201,"rt":0.156,"bytes":512,"src":"192.168.1.101"}
Field Descriptions
- ts: ISO 8601 timestamp when the request was processed
- host: Server hostname where the request was handled
- path: Request path (without query parameters)
- method: HTTP method (GET, POST, etc.)
- status: HTTP response status code
- rt: Response time in seconds
- bytes: Response size in bytes
- src: Client IP address
๐ง Advanced Configuration
Queue-Based Processing
For high-traffic applications, you can enable asynchronous processing using Laravel queues. This prevents the HTTP request from being blocked while logs are sent to Tailstream:
TAILSTREAM_USE_QUEUE=true TAILSTREAM_QUEUE_NAME=tailstream TAILSTREAM_QUEUE_CONNECTION=redis
When queue processing is enabled:
- Log batches are dispatched to the specified queue instead of being sent synchronously
- The queue job includes retry logic (3 attempts with 60-second backoff)
- Your queue workers will handle the actual transmission to Tailstream
- This reduces request latency and provides better fault tolerance
Requirements:
- Ensure your queue system is properly configured and running
- Queue workers must be active to process the jobs
- Consider using a reliable queue driver like Redis or database for production
Sampling for High-Traffic Apps
'sampling_rate' => 0.1, // Log 10% of requests
Exclude Specific Paths
'excluded_paths' => [ 'telescope/*', 'horizon/*', '_ignition/*', 'health-check', 'up', 'favicon.ico', '*.css', '*.js', '*.map', 'storage/*', ],
๐งช Testing
composer test
๐ Laravel Integration
Middleware Registration
The package automatically registers middleware globally. To disable:
'auto_register_middleware' => false,
Then manually register:
// bootstrap/app.php ->withMiddleware(function (Middleware $middleware) { $middleware->append(TailstreamLogger::class); })
๐ Monitoring & Debugging
Request Correlation
Every request gets a unique UUID that's included in all logs during that request, making it easy to trace issues across your application.
๐ Batching Strategy
- Batch Size: Process when 50 entries are collected (configurable)
- Periodic Flush: Process every 10 requests to prevent logs sitting too long (configurable)
- Cache-Based: Uses your configured cache driver (Redis recommended)
- Queue Support: Optional asynchronous processing for high-traffic applications
๐ง Management Commands
The package includes artisan commands for batch management:
# Check batch status php artisan tailstream:flush --status # Manually flush pending logs php artisan tailstream:flush # Clear batch without processing php artisan tailstream:flush --clear
๐ License
This package is open-sourced software licensed under the MIT license.
๐ค Contributing
Contributions are welcome! Please see CONTRIBUTING.md for details.
๐ Bug Reports
If you discover a bug, please open an issue on GitHub.