{"id":18407527,"url":"https://github.com/simplecomplex/php-jsonlog","last_synced_at":"2026-05-14T23:14:17.016Z","repository":{"id":57051251,"uuid":"92948048","full_name":"simplecomplex/php-jsonlog","owner":"simplecomplex","description":"PSR-3 logger filing as JSON","archived":false,"fork":false,"pushed_at":"2020-05-02T07:20:06.000Z","size":145,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-16T04:42:40.480Z","etag":null,"topics":["json","logger","php","php7","psr","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simplecomplex.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.txt","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-31T13:24:42.000Z","updated_at":"2022-02-12T09:13:51.000Z","dependencies_parsed_at":"2022-08-24T03:41:03.303Z","dependency_job_id":null,"html_url":"https://github.com/simplecomplex/php-jsonlog","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplecomplex%2Fphp-jsonlog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplecomplex%2Fphp-jsonlog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplecomplex%2Fphp-jsonlog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simplecomplex%2Fphp-jsonlog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simplecomplex","download_url":"https://codeload.github.com/simplecomplex/php-jsonlog/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631682,"owners_count":21136562,"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","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":["json","logger","php","php7","psr","psr-3"],"created_at":"2024-11-06T03:14:23.923Z","updated_at":"2025-10-07T15:05:36.807Z","avatar_url":"https://github.com/simplecomplex.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"## JsonLog ##\n\nPSR-3 logger which files events as JSON.\n\n\n### Columns ###\n\nColumns are configuration-wise split in groups of _event_-, _request_- and _site_-specific items.  \nFor every column there's a ```JsonLogEvent``` method and a JSON bucket name (this lists the bucket names).\n\nSeveral columns get skipped if their equivalent method returns empty string (that's the un-bold items).\n\nSome column's must be set via the PSR-3 logger methods' ```$context``` argument.\n\nAll column values are string, except the _code_ column.\n\n##### Event #####\n- **message**\n- **@timestamp**: ISO-8601\n- **message_id**: fairly random ID, using site ID as salt\n- correlation_id: set via ```$context```\n- **subtype**: set via ```$context```, default ```component```\n- **level**: ```emergency|alert|critical|error|warning|notice|info|debug```\n- **code**: integer, set via ```$context```; default ```0```\n- exception: PHP throwable, via ```$context```; becomes class name\n- trunc: ```(original byte length/truncated length)```\n- user: set via ```$context```, or override ```JsonLogEvent::user()``` in extending class\n- session: set via ```$context```, override ```JsonLogEvent::session()``` in extending class\n\n##### Request #####\n\n- **method**: HTTP request method; ```cli``` if in CLI mode\n- **request_uri**: HTTP request URI; console arguments if in CLI mode\n- referer: HTTP referrer (sanitized)\n- client_ip: remote address, filtered for _reverse_proxy_addresses_\n- useragent: sanitized\n\n##### Site #####\n\n- **type**: _type_ setting; default ```webapp```\n- **host**: ```$_SERVER['SERVER_NAME']``` or empty\n- **site_id**: _siteid_ setting\n- canonical: _canonical_ setting\n- tags:  _tags_ setting\n\n### Settings ###\n\nAre set via 'global' [SimpleComplex Config](https://github.com/simplecomplex/php-config),\nsection ```lib_simplecomplex_jsonlog```.\n\nThe simplest approach to that is to **use environment variables**, like  \n```SetEnv lib_simplecomplex_jsonlog__threshold 7```.  \n```JsonLog``` constructor uses environment variables as fallback.\n\n- (int) **threshold**: less severe events are skipped (not logged); default ```4``` (~```warning```)\n- (str) **siteid**: defaults to name of directory above document root\n- (str) **path**: default ```/var/log/[apache2|httpd|nginx]```/php-jsonlog\n- (int) **truncate** (Kb): truncate _message_ so that event JSON doesn't exceed that length; default ```32```\n- (str) **reverse_proxy_addresses**: comma-separated list of IP addresses; default empty\n- (str) **type**: default ```webapp```\n- (str) **canonical**: site identifier across multiple instances; default empty\n- (str) **tags**: comma-separated list; default empty\n- (str) **reverse_proxy_header**: default ```HTTP_X_FORWARDED_FOR```\n- (str) **file_time**: set to empty or ```none``` to write to the same log file forever; default ```Ymd```\n- (str) **format**: ```default|pretty|prettier```; ```prettier``` is not valid JSON, but easier on the eyes\n\n#### Recommended settings ####\n\n##### All environments #####\n\n- **siteid**: use something more meaningful than the default\n- **truncate**: way higher, to like ```256```, if your system generates giant dumps or traces\n\n##### Prod environment #####\n\n- **reverse_proxy_addresses**: look out for proxy servers\n\n##### Dev/test environment #####\n\n- **threshold**: ```7``` (~```debug```)\n- **path**: make it closer to home if no log extractor (like [Kibana+ElasticSearch](https://www.elastic.co)) running\n- **format**: ```prettier``` if no log extractor running\n\n\n### CLI commands ###\n\n```bash\n# List all json-log commands and their help.\nphp cli.php json-log -h\n# One command's help.\nphp cli.php json-log-xxx -h\n\n# Check/enable JsonLog to write logs.\nphp cli.php json-log-committable\n\n# Truncate current log file.\nphp cli.php json-log-truncate\n```\n\n### Dependency injection container ID: logger ###\n\nRecommendation: access (and thus instantiate) JsonLog via DI container ID 'logger'.  \nSee [SimpleComplex Utils](https://github.com/simplecomplex/php-utils) ``` Dependency ```.\n\n### Requirements ###\n\n- PHP \u003e=7.0\n- [PSR-3 Log](https://github.com/php-fig/log)\n- [SimpleComplex Utils](https://github.com/simplecomplex/php-utils)\n\n##### Suggestions #####\n\n- [SimpleComplex Inspect](https://github.com/simplecomplex/inspect)\n- [SimpleComplex Config](https://github.com/simplecomplex/php-config)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplecomplex%2Fphp-jsonlog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimplecomplex%2Fphp-jsonlog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimplecomplex%2Fphp-jsonlog/lists"}