Download the PHP package schaefersoft/laravel-seq without Composer
On this page you can find all versions of the php package schaefersoft/laravel-seq. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download schaefersoft/laravel-seq
More information about schaefersoft/laravel-seq
Files in schaefersoft/laravel-seq
Package laravel-seq
Short Description Structured logging to Seq for Laravel. Ships batched CLEF events after the response is sent.
License MIT
Homepage https://github.com/schaefersoft/laravel-seq
Informations about the package laravel-seq
Laravel Seq
Structured logging from Laravel to Seq. Placeholders like {order_id} become properties you
can search, filter and chart on, and exceptions arrive with their full stack trace.
Events are buffered and shipped in batches after the response has been sent, so logging never slows down or breaks your application.
Features
- A
seqlog driver and a ready-to-useseqchannel, registered automatically - PSR-3 placeholders become Seq message templates, context becomes event properties
- Exceptions, including previous exceptions, land in Seq's exception view
Log::withContext(),Log::shareContext()and Laravel'sContextare shipped as properties- Batched delivery after the response, between queue jobs and when a process ends, even after fatal errors
- Short timeouts, and delivery failures never reach your application
- A circuit breaker pauses shipping while Seq is unreachable, so requests and workers are not held up
- Oversized events are trimmed instead of failing the whole batch
php artisan seq:testto verify the connection andSeq::fake()for your own tests
Requirements
- PHP 8.2+
- Laravel 12 or 13
- Seq 2023.4+
Installation
The service provider is discovered automatically.
Quick start
Point the package to your Seq server. Without SEQ_URL, nothing is shipped:
Add the seq channel to your log stack:
Check that everything works:
Configuration
| Variable | Default | Description |
|---|---|---|
SEQ_URL |
– | Base URL of your Seq server, nothing is shipped without it |
SEQ_API_KEY |
– | API key, sent as X-Seq-ApiKey header |
SEQ_ENABLED |
true |
Set to false to stop shipping events |
SEQ_LEVEL |
LOG_LEVEL or debug |
Minimum level shipped to Seq |
SEQ_TIMEOUT |
2 |
Request timeout in seconds |
SEQ_CONNECT_TIMEOUT |
1 |
Connection timeout in seconds |
SEQ_BATCH_SIZE |
100 |
Maximum number of events per request |
SEQ_FLUSH_INTERVAL |
5 |
Maximum age in seconds of buffered events in long-running processes, 0 disables it |
SEQ_MAX_EVENT_SIZE |
262144 |
Maximum event size in bytes, matching Seq's default |
SEQ_CIRCUIT_BREAKER |
30 |
Seconds to pause shipping after Seq could not be reached, 0 disables it |
SEQ_CIRCUIT_BREAKER_STORE |
– | Cache store for the circuit breaker state, see Failures |
Publish the configuration file to change the defaults:
Properties
Every event carries the properties from config/seq.php. By default these are Application and Environment, which
lets you tell applications apart on a shared Seq server:
Properties with a null value are skipped. Context values with the same name take precedence.
Channels
The registered seq channel reads everything from config/seq.php. Define channels with the seq driver in
config/logging.php to override any of those options per channel, for example to ship audit events to a second Seq
server:
Besides the options of config/seq.php, channels accept bubble, name, processors and Laravel's tap. Processors
only apply to the events shipped to Seq, even when the channel is part of a stack. properties defined on a channel
replace the default properties.
Usage
Keep the message constant and pass the values as context:
Seq receives the event as CLEF:
Seq renders the message as Order 1042 placed by [email protected], lets you filter with order_id = 1042 and groups all
events of the same template. Interpolating values yourself ("Order {$id} placed") loses all of that.
Exceptions
Exceptions passed in the exception context key are shipped to Seq's exception field, including previous exceptions
and stack traces. Laravel's exception handler does this for every reported exception, so they show up in Seq as soon as
the seq channel is part of your default stack.
Context
Context from Log::withContext(), Log::shareContext() and Laravel's Context facade is shipped as properties:
Values
| Value | Shipped as |
|---|---|
| Strings, numbers, booleans, arrays | As is |
| Dates | ISO 8601 string |
| Enums | Value of backed enums, name otherwise |
JsonSerializable and Arrayable, like models |
Structured object with a $type |
Stringable |
String |
| Other objects | Public properties with a $type |
Braces that are not placeholders are escaped, so Blade {{ $name }} failed is rendered exactly as written. Property
names starting with @ are escaped as CLEF requires.
Levels
| Laravel | Seq |
|---|---|
debug |
Debug |
info, notice |
Information |
warning |
Warning |
error |
Error |
critical, alert, emergency |
Fatal |
Delivery
Events are buffered in memory and shipped in batches:
| Situation | Events are shipped |
|---|---|
| HTTP requests | After the response has been sent |
| Artisan commands | When the command has finished |
| Queue workers and Horizon | After every job and when the worker stops |
| Octane | After every request |
| Every process | When the process ends, even after a fatal error |
A batch is also shipped as soon as SEQ_BATCH_SIZE events are buffered, or when an event is logged while the oldest
buffered event is older than SEQ_FLUSH_INTERVAL seconds. This keeps long-running commands close to real time. In your
own long-running loops, ship the buffer explicitly:
Failures
Requests use short timeouts. Delivery errors are swallowed and the affected events are dropped, so logging never throws
and never blocks longer than the timeouts. After a connection failure, the remaining batches of that flush are dropped
instead of waiting for more timeouts. Keep a local channel in your stack, like LOG_STACK=daily,seq, to not lose any
events, and run php artisan seq:test to find out what is wrong.
When Seq cannot be reached or does not answer in time, a circuit breaker pauses shipping for SEQ_CIRCUIT_BREAKER
seconds and drops the events of that time. Otherwise every request would wait for the timeouts, and under load the
PHP-FPM pool would fill up. Error responses from Seq do not trip the circuit breaker. Its state is kept per Seq server:
| Runtime | State is kept in |
|---|---|
| PHP-FPM with APCu | APCu, shared by all workers of the pool |
| Octane, queue workers, commands | Memory of the process |
SEQ_CIRCUIT_BREAKER_STORE set |
The Laravel cache store of that name, like redis |
Without APCu, PHP-FPM forgets the state after every request. Install APCu or set SEQ_CIRCUIT_BREAKER_STORE to a
cache store that responds quickly, since it is queried before every delivery.
Large events
Seq rejects events larger than 256 KB and requests larger than 10 MB, and a single rejected event makes it reject the whole request. To prevent that, requests are split into chunks of at most 1 MB, and oversized events are trimmed:
- The largest properties are removed and listed in
DroppedProperties. - If that is not enough, the message and exception messages are truncated.
- As a last resort, the event is replaced by a placeholder with a sample of the original.
If you raised the event size limit of your Seq server, raise SEQ_MAX_EVENT_SIZE as well.
Checking the connection
seq:test sends a test event with the settings of a channel and explains what went wrong if Seq rejects it:
php artisan about shows the Seq configuration as well.
Testing
Seq requests do not go through the Http facade, so Http::fake() neither catches nor counts them. Disable shipping in
your phpunit.xml:
Or fake Seq and assert what would have been shipped:
Running Seq locally
Seq is then available at http://localhost:5341. Set SEQ_URL=http://localhost:5341 to ship to it.
Development
The integration tests run against a real Seq server, for example the container from Running Seq locally:
Changelog
See CHANGELOG.md.
License
The MIT License (MIT). See LICENSE.
All versions of laravel-seq with dependencies
illuminate/cache Version ^12.0|^13.0
illuminate/console Version ^12.0|^13.0
illuminate/contracts Version ^12.0|^13.0
illuminate/http Version ^12.0|^13.0
illuminate/log Version ^12.0|^13.0
illuminate/support Version ^12.0|^13.0
monolog/monolog Version ^3.0