{"id":16075253,"url":"https://github.com/ricardoboss/php-seq","last_synced_at":"2025-10-04T02:27:47.175Z","repository":{"id":165971929,"uuid":"640710998","full_name":"ricardoboss/php-seq","owner":"ricardoboss","description":"A PHP library for Seq HTTP ingestion","archived":false,"fork":false,"pushed_at":"2023-06-18T13:54:48.000Z","size":155,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-13T11:32:34.778Z","etag":null,"topics":["datalust","logging","php","psr-3","seq"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/ricardoboss/php-seq","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ricardoboss.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-15T00:40:34.000Z","updated_at":"2023-05-16T11:21:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"84d0b018-b5f8-4709-aac3-0e6253b32557","html_url":"https://github.com/ricardoboss/php-seq","commit_stats":{"total_commits":57,"total_committers":1,"mean_commits":57.0,"dds":0.0,"last_synced_commit":"aca4b4c89b88d2978de2eec3526af8f07bdbdc21"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/ricardoboss/php-seq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricardoboss%2Fphp-seq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricardoboss%2Fphp-seq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricardoboss%2Fphp-seq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricardoboss%2Fphp-seq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ricardoboss","download_url":"https://codeload.github.com/ricardoboss/php-seq/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ricardoboss%2Fphp-seq/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278254666,"owners_count":25956644,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-04T02:00:05.491Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["datalust","logging","php","psr-3","seq"],"created_at":"2024-10-09T09:03:33.223Z","updated_at":"2025-10-04T02:27:47.143Z","avatar_url":"https://github.com/ricardoboss.png","language":"PHP","readme":"[Seq]: https://datalust.co/seq\n[License]: ./LICENSE.md\n[create issue]: https://github.com/ricardoboss/php-seq/issues/new\n[CLEF format]: https://clef-json.org/\n[message templates]: https://messagetemplates.org/\n[Reified properties]: https://docs.datalust.co/docs/posting-raw-events#reified-properties\n[`example`]: ./example\n[guzzlehttp/guzzle]: https://packagist.org/packages/guzzlehttp/guzzle\n[here on Seq's website]: https://docs.datalust.co/docs/using-serilog#dynamic-level-control\n[this brief blog post]: https://nblumhardt.com/2016/02/remote-level-control-in-serilog-using-seq/\n\n[![Unit Tests](https://github.com/ricardoboss/php-seq/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/ricardoboss/php-seq/actions/workflows/unit-tests.yml)\n[![](https://img.shields.io/packagist/v/ricardoboss/php-seq)](https://packagist.org/packages/ricardoboss/php-seq)\n\n# php-seq\n\nA PHP library for [Seq] HTTP ingestion.\n\n## Installation\n\n```\ncomposer require ricardoboss/php-seq\n```\n\n## Usage\n\n```php\n// 0. gather dependencies (preferably using dependency injection)\n$httpClient = getPsr18Client(); // PSR-18 (HTTP Client)\n$requestFactory = getPsr17RequestFactory(); // PSR-17 (HTTP Factories)\n$streamFactory = getPsr17StreamFactory(); // PSR-17 (HTTP Factories)\n\n// 1. create the Seq client\n$clientConfig = new SeqHttpClientConfiguration(\"https://my-seq-host:5341/api/events/raw\", \"my-api-key\");\n$seqClient = new SeqHttpClient($clientConfig, $httpClient, $requestFactory, $streamFactory);\n\n// 2. create the logger\n$loggerConfig = new SeqLoggerConfiguration();\n$logger = new SeqLogger($loggerConfig, $seqClient);\n\n// 3. start logging!\n$logger-\u003esend(SeqEvent::info(\"Hello from PHP!\"));\n// or\n$logger-\u003einfo(\"Hello via PSR-3!\"); // or $logger-\u003elog(\\Psr\\Log\\LogLevel::INFO, \"...\");\n\n// using message templates:\n$logger-\u003einfo('This is PHP {PhpVersion}', ['PhpVersion' =\u003e PHP_VERSION]);\n\n// (optional) 4. force sending all buffered events\n$logger-\u003eflush();\n```\n\n\u003e **Note**\n\u003e\n\u003e All events get flushed automatically when the loggers `__destruct` method is called (i.e. at latest when the runtime shuts down).\n\nYou can use the example project in the [`example`] folder to try different things out.\nIt uses [guzzlehttp/guzzle] as its PSR implementations.\n\n## Configuration\n\nThe configuration is split up between the actual client, sending the requests and the logger gathering events and forwarding them to the client.\nThis makes it possible to create multiple loggers with different contexts/minimum log levels using the same client.\nAlso, it enables us to implement new clients for other interfaces in the future (see “Future Scope” below).\n\n### `SeqHttpClientConfiguration`\n\n| Parameter     | Type           | Default | Description                                                                                                                                                                                        |\n|---------------|----------------|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `$endpoint`   | `string`       | -       | The endpoint to use. Must not be empty. Usually has the form \"https://seq-host:5341/api/events/raw\"                                                                                                |\n| `$apiKey`     | `string\\|null` | `null`  | If your Seq instance requires authentication, you need to provide your API key here. If given, it must not be empty.                                                                               |\n| `$maxRetries` | `int`          | `3`     | The number of tries before throwing an exception if sending the events fails. Exceptions implementing `\\Psr\\Http\\Client\\NetworkExceptionInterface` bypass this limit and are immediately rethrown. |\n\n### `SeqLoggerConfiguration`\n\n| Parameter        | Type          | Default | Description                                                                                                                                  |\n|------------------|---------------|---------|----------------------------------------------------------------------------------------------------------------------------------------------|\n| `$backlogLimit`  | `int`         | `10`    | The amount of events to collect before sending a batch to the server. You can explicitly flush all buffered events using the `flush` method. |\n| `$globalContext` | `array\\|null` | `null`  | A key-value list that gets attached to all events logged using this logger.                                                                  |\n\n## Advanced usage\n\n### Message templates \u0026 context\n\nSeq supports the [message templates] syntax.\nYou can use it too using the context parameter:\n\n```php\n$username = \"EarlyBird91\";\n\n// Will log \"Created EarlyBird91 user\" to Seq with the \"username\" attribute set to \"EarlyBird91\"\n$logger-\u003einfo(\"Created {username} user\", ['username' =\u003e $username]);\n```\n\n\u003e **Note**\n\u003e\n\u003e The context values will be converted to strings.\n\u003e If they aren't scalar or `Stringable` objects, they are encoded using `json_encode`.\n\n### Custom Seq events\n\nSeq uses the [CLEF format] for HTTP ingestion, which is used by this library.\nFor your convenience, you can directly access all the properties of the CLEF format using the `SeqEvent` class.\n\nJust create a new instance and send it using the `SeqLogger` or encode it using `json_encode`:\n\n```php\n$event = new SeqEvent(\n    new DateTimeImmutable(),\n    \"message\",\n    \"messageTemplate\",\n    \"level\",\n    new Exception(\"exception\"),\n    123,\n    ['attribute' =\u003e 'rendered'],\n    ['tag' =\u003e 'value'],\n);\n\n$logger-\u003esend($event);\n// or\necho json_encode($event); // {\"@t\":\"2023-05-16T12:00:01.123456+00:00\",\"@mt\":\"messageTemplate\",...}\n```\n\nNote that you still need to validate the event yourself if you create it that way.\nYou can check the requirements from Seq here: [Reified properties]\n\nEscaping of user properties using `@` is done automatically when encoding the event to JSON.\n\n### Minimum log level\n\nYou can specify the minimum log level a logger will buffer and send to Seq using the `$minimumLogLevel` constructor\nparameter of the `SeqLoggerConfiguration` class:\n\n```php\n$config = new SeqLoggerConfiguration(minimumLogLevel: SeqLogLevel::Warning);\n```\n\nThis will allow only `Warning` or more critical events to be sent to Seq (like `Error` and `Fatal`).\n\nYou can also adjust the minimum log level of the logger at runtime:\n\n```php\n$previousLogLevel = $logger-\u003egetMinimumLogLevel();\n\n$logger-\u003esetMinimumLogLevel(SeqLogLevel::Information);\n```\n\n### Dynamic Level Control\n\nSeq supports a scheme called \"Dynamic Level Control\", which allows the client to adjust its minimum log level based on\nwhat is configured for its API key.\n\n`php-seq` also supports this and will adjust the minimum log level of each logger based on what Seq responds.\n\nYou can read up on Dynamic Level Control [here on Seq's website] or in [this brief blog post] by Nicholos Blumhardt.\n\n## Error handling\n\nAll exceptions thrown by this library implement the `\\RicardBoss\\PhpSeq\\Contract\\SeqException` interface.\nThis makes it easy to catch any exception wrapped by this library.\n\n## Future Scope\n\nThe aim for this library is to provide simple logging for Seq in PHP and stay compatible with current PHP and Seq versions.\n\nA possible addition for this library could be to use GELF instead of HTTP using the `sockets` extension, but this is not planned for now.\n\n## Contributing\n\nContributions in all forms are welcome! If you are missing a specific feature or something isn't working as expected,\nplease create an issue on GitHub: [create issue].\n\nIf you can, you are encouraged to create a pull request. Please make sure you add tests for the functionality you\nadd/change and make sure they pass.\n\n## License\n\nThis project is licensed under the MIT license. For more information, see [License].\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fricardoboss%2Fphp-seq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fricardoboss%2Fphp-seq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fricardoboss%2Fphp-seq/lists"}