{"id":19335021,"url":"https://github.com/czim/monolog-json-context","last_synced_at":"2025-04-23T00:31:46.027Z","repository":{"id":56960956,"uuid":"138506432","full_name":"czim/monolog-json-context","owner":"czim","description":"Monolog extension for custom JSON-format logging","archived":false,"fork":false,"pushed_at":"2023-04-07T13:41:52.000Z","size":11,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T15:59:21.693Z","etag":null,"topics":["filebeat","formatter","json","logging","logstash","monolog"],"latest_commit_sha":null,"homepage":null,"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/czim.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-24T18:37:52.000Z","updated_at":"2023-04-07T13:40:28.000Z","dependencies_parsed_at":"2022-08-21T09:20:59.442Z","dependency_job_id":null,"html_url":"https://github.com/czim/monolog-json-context","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/czim%2Fmonolog-json-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/czim%2Fmonolog-json-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/czim%2Fmonolog-json-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/czim%2Fmonolog-json-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/czim","download_url":"https://codeload.github.com/czim/monolog-json-context/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250348285,"owners_count":21415893,"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":["filebeat","formatter","json","logging","logstash","monolog"],"created_at":"2024-11-10T03:04:30.789Z","updated_at":"2025-04-23T00:31:45.802Z","avatar_url":"https://github.com/czim.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n[![Latest Version on Packagist][ico-version]][link-packagist]\n[![Software License][ico-license]](LICENSE.md)\n[![Build Status](https://travis-ci.org/czim/monolog-json-context.svg?branch=master)](https://travis-ci.org/czim/monolog-json-context)\n[![Coverage Status](https://coveralls.io/repos/github/czim/monolog-json-context/badge.svg?branch=master)](https://coveralls.io/github/czim/monolog-json-context?branch=master)\n\n\n# JSON Context for Monolog\n\nSimple helper package with Monolog formatters.\n\nThis helps to set up consistent JSON context log output. \nThe aim of these formatters is to write log lines that may easily be grokked by logstash.\n\n\n## Example Filebeat + Logstash setup\n\n### Filebeat configuration\n\n```yaml\n# ...\n\nfilebeat.prospectors:\n\n- type: log\n  enabled: true\n  paths:\n    - /usr/some/path/*.log\n  tail_files: true\n  multiline:\n    pattern: '^\\[[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}'\n    negate: true\n    match: after\n  fields:\n    source: context_json\n    index: testing\n\n# ...\n```\n\n### Logstash configuration\n\n```\ninput {\n  beats {\n    port =\u003e 5000\n  }\n}\n\nfilter {\n\n    # Split up the custom message into fields\n    grok {\n      match =\u003e { \"message\" =\u003e \"\\[%{TIMESTAMP_ISO8601:timestamp}\\] %{DATA:channel}\\.%{LOGLEVEL:severity}: %{GREEDYDATA:context}\" }\n      overwrite =\u003e [ \"message\", \"context\" ]\n    }\n    \n    # Take the timestamp from the log line and use it for @timestamp\n    date {\n      match =\u003e [ \"timestamp\", \"yyyy-MM-dd HH:mm:ss\" ]\n    }\n    \n    # Clean up (optional)\n    mutate {\n      remove_field =\u003e [\"timestamp\", \"prospector\", \"beat\"]\n    }\n    \n    # Pull fields.index up one level, add it so we can use it in the output.\n    # Optional, but I needed this to get `index =\u003e \"%{index}-%{+YYYY.MM}\"` \n    # working for the elasticsearch output.\n    if (![fields][index]) {\n      mutate {\n        add_field =\u003e { \"index\" =\u003e \"default\" }\n      }\n    } else {\n      mutate {\n        add_field =\u003e { \"index\" =\u003e \"%{[fields][index]}\" }\n        remove_field =\u003e \"[fields][index]\"\n      }\n    }\n    \n    # Make sure to interpret the context field as JSON\n    json {\n        source =\u003e \"context\"\n    }\n}\n\noutput {\n  elasticsearch {\n    hosts =\u003e \"elasticsearch:9200\"\n    index =\u003e \"%{index}-%{+YYYY.MM}\"\n  }\n}\n```\n\n### PHP\n\n```php\n\u003c?php\n$formatter = new \\Czim\\MonologJsonContext\\Formatters\\JsonContextFormatter(null, 'test-application');\n\n$logger = (new \\Monolog\\Logger('channel'))\n    -\u003epushHandler(\n        (new \\Monolog\\Handler\\RotatingFileHandler('/usr/some/path/test.log', 7))\n            -\u003esetFormatter(\n                \n            )\n    );\n\n$logger-\u003einfo('Your message', ['testing' =\u003e true, 'category' =\u003e 'documentation.test']);\n```\n\n\n## Credits\n\n- [All Contributors][link-contributors]\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n\n[ico-version]: https://img.shields.io/packagist/v/czim/monolog-json-context.svg?style=flat-square\n[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square\n[ico-downloads]: https://img.shields.io/packagist/dt/czim/monolog-json-context.svg?style=flat-square\n\n[link-packagist]: https://packagist.org/packages/czim/monolog-json-context\n[link-downloads]: https://packagist.org/packages/czim/monolog-json-context\n[link-author]: https://github.com/czim\n[link-contributors]: ../../contributors\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fczim%2Fmonolog-json-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fczim%2Fmonolog-json-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fczim%2Fmonolog-json-context/lists"}