{"id":21803006,"url":"https://github.com/nostadt/php-psr3-log-context","last_synced_at":"2026-05-18T08:03:04.120Z","repository":{"id":184628303,"uuid":"671452793","full_name":"nostadt/php-psr3-log-context","owner":"nostadt","description":"Structured PSR-3 Logging","archived":false,"fork":false,"pushed_at":"2024-01-06T19:20:51.000Z","size":4027,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"development","last_synced_at":"2025-03-21T07:16:10.440Z","etag":null,"topics":["logging","php","psr-3"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nostadt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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-07-27T10:54:53.000Z","updated_at":"2023-10-15T11:18:45.000Z","dependencies_parsed_at":"2023-10-16T03:34:07.038Z","dependency_job_id":"e9e15166-514a-4df6-a6fe-cac5ee517b80","html_url":"https://github.com/nostadt/php-psr3-log-context","commit_stats":null,"previous_names":["nostadt/php-psr3-log-context"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/nostadt/php-psr3-log-context","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nostadt%2Fphp-psr3-log-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nostadt%2Fphp-psr3-log-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nostadt%2Fphp-psr3-log-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nostadt%2Fphp-psr3-log-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nostadt","download_url":"https://codeload.github.com/nostadt/php-psr3-log-context/tar.gz/refs/heads/development","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nostadt%2Fphp-psr3-log-context/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33170442,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-18T05:43:36.989Z","status":"ssl_error","status_checked_at":"2026-05-18T05:43:19.133Z","response_time":71,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["logging","php","psr-3"],"created_at":"2024-11-27T11:36:59.167Z","updated_at":"2026-05-18T08:03:04.086Z","avatar_url":"https://github.com/nostadt.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PSR-3 Log-Context - Structured PSR-3 Logging\n\n[![CI Process](https://github.com/nostadt/php-psr3-log-context/actions/workflows/default.yml/badge.svg)](https://github.com/nostadt/php-psr3-log-context/actions/workflows/default.yml)\n[![packagist.org](https://img.shields.io/packagist/v/nostadt/psr3-log-context)](https://packagist.org/packages/nostadt/psr3-log-context)\n\n## Preamble\n\nEspecially for larger projects logging is essential. You do want to have all the data you need when looking in the past.\nNothing is worse than having a serious issue on the production system but lacking of helpful context information.\nThis small package makes it easy to log in a structured manner without cluttering your code.\n\n## Available classes and interface\n\n| Class                                | Description                                                                    |\n|--------------------------------------|--------------------------------------------------------------------------------|\n| `LogData`                            | Key=\u003eValue combo to forbid bad values                                          |\n| `LogContext`                         | Storage for `LogData` and `toArray` method that will be passed as 2nd argument |\n| `LogContextConvertibleInterface`     | Make any custom class LogContext compatible.                                   |\n\n**Further link/s**\n- https://www.php-fig.org/psr/psr-3/\n\n## Examples\n\n**Use LogContext::createFromException**\n\nThis is the recommended way when dealing with Exceptions, unless they implement `LogContextConvertibleInterface`.\n\n```php\n\u003c?php\n\nuse \\Nostadt\\Psr3LogContext\\LogContext;\n\ntry {\n    doSomething();\n} catch (\\Exception $exception) {\n    $this-\u003elogger-\u003ewarning(\n        $exception-\u003egetMessage(),\n        LogContext::createFromException($exception)-\u003etoArray()\n    );\n}\n```\n\n**Use LogContextConvertibleInterface**\n\nThis is the recommend way, because it truly simplifies creating the log-context array.\n\n```php\n\u003c?php\n\nclass User implements \\Nostadt\\Psr3LogContext\\LogContextConvertibleInterface\n{\n    public int $id;\n    public bool $activated;\n    public string $name;\n\n    public function asLogContext(): \\Nostadt\\Psr3LogContext\\LogContext\n    {\n        return new \\Nostadt\\Psr3LogContext\\LogContext(\n            new \\Nostadt\\Psr3LogContext\\ValueObject\\LogData('user_id', (string)$this-\u003eid),\n            new \\Nostadt\\Psr3LogContext\\ValueObject\\LogData('user_activated', $this-\u003eactivated ? 'true' : 'false'),\n            new \\Nostadt\\Psr3LogContext\\ValueObject\\LogData('user_name', $this-\u003ename),\n        );\n    }\n}\n\n$user = new User();\n$user-\u003eid = 1;\n$user-\u003eactivated = true;\n$user-\u003ename = 'John Doe';\n\n$logger-\u003ewarning('My Message', $user-\u003easLogContext()-\u003etoArray());\n```\n\n**Merge multiple LogContexts**\n\nWith previous `User`-class in mind we can merge LogContext-objects.\n\n```php\n\u003c?php\n\nuse \\Nostadt\\Psr3LogContext\\LogContext;\n\ntry {\n    registerUser($user);\n} catch (\\Exception $exception) {\n    $this-\u003elogger-\u003ewarning(\n        $exception-\u003egetMessage(),\n        LogContext::createFromException($exception)-\u003emergeLogContext($user-\u003easLogContext())-\u003etoArray()\n    );\n}\n```\n\n**Create a LogContext from the scratch**\n\nThis can be used in situations in which `LogContext` is not available.\n\n```php\n\u003c?php\n\n$logContext = new \\Nostadt\\Psr3LogContext\\LogContext(\n    new \\Nostadt\\Psr3LogContext\\ValueObject\\LogData('user_uid', '1'),\n    new \\Nostadt\\Psr3LogContext\\ValueObject\\LogData('user_activated', 'true'),\n    new \\Nostadt\\Psr3LogContext\\ValueObject\\LogData('user_name', 'John Doe'),\n);\n\n$logger-\u003ewarning('My Message', $logContext-\u003etoArray());\n```\n\n## Development\n\n**Requirements:**\n\n- [Docker](https://www.docker.com/)\n- [Make](https://www.selflinux.org/selflinux/html/make01.html)\n\nIf you start fresh, execute:\n```bash\nmake init\nmake start\n```\n\nIf you want to run code-quality checks, execute:\n```bash\nmake test\nmake lint\n```\n\nIf you are done working, execute:\n```bash\nmake stop\n```\n\nIf you want to continue working, execute:\n```bash\nmake start\n```\n\nIf you want to clean up the system, execute:\n```bash\nmake clean\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnostadt%2Fphp-psr3-log-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnostadt%2Fphp-psr3-log-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnostadt%2Fphp-psr3-log-context/lists"}