{"id":14966413,"url":"https://github.com/yiisoft/log","last_synced_at":"2025-04-12T23:34:32.176Z","repository":{"id":38817915,"uuid":"140870898","full_name":"yiisoft/log","owner":"yiisoft","description":"PSR-3 compatible logger","archived":false,"fork":false,"pushed_at":"2024-10-25T05:02:50.000Z","size":314,"stargazers_count":40,"open_issues_count":5,"forks_count":17,"subscribers_count":20,"default_branch":"master","last_synced_at":"2024-10-29T14:35:38.723Z","etag":null,"topics":["hacktoberfest","log","logger","logging","psr-3","yii3"],"latest_commit_sha":null,"homepage":"https://www.yiiframework.com/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yiisoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"open_collective":"yiisoft","github":["yiisoft"]}},"created_at":"2018-07-13T16:41:23.000Z","updated_at":"2024-10-25T05:02:54.000Z","dependencies_parsed_at":"2024-11-05T16:48:25.984Z","dependency_job_id":null,"html_url":"https://github.com/yiisoft/log","commit_stats":{"total_commits":217,"total_committers":26,"mean_commits":8.346153846153847,"dds":0.7050691244239631,"last_synced_commit":"f8e05c919dc3848d3174f95078e5c7091d53b641"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Flog","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Flog/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Flog/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Flog/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yiisoft","download_url":"https://codeload.github.com/yiisoft/log/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246748438,"owners_count":20827311,"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":["hacktoberfest","log","logger","logging","psr-3","yii3"],"created_at":"2024-09-24T13:36:20.957Z","updated_at":"2025-04-04T02:07:12.697Z","avatar_url":"https://github.com/yiisoft.png","language":"PHP","funding_links":["https://opencollective.com/yiisoft","https://github.com/sponsors/yiisoft"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/yiisoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://yiisoft.github.io/docs/images/yii_logo.svg\" height=\"100px\" alt=\"Yii\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eYii Logging Library\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\n[![Latest Stable Version](https://poser.pugx.org/yiisoft/log/v)](https://packagist.org/packages/yiisoft/log)\n[![Total Downloads](https://poser.pugx.org/yiisoft/log/downloads)](https://packagist.org/packages/yiisoft/log)\n[![Build status](https://github.com/yiisoft/log/actions/workflows/build.yml/badge.svg)](https://github.com/yiisoft/log/actions/workflows/build.yml)\n[![Code coverage](https://codecov.io/gh/yiisoft/log/graph/badge.svg?token=4CSPCRMGQM)](https://codecov.io/gh/yiisoft/log)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Flog%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/log/master)\n[![static analysis](https://github.com/yiisoft/log/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/log/actions?query=workflow%3A%22static+analysis%22)\n[![type-coverage](https://shepherd.dev/github/yiisoft/log/coverage.svg)](https://shepherd.dev/github/yiisoft/log)\n\nThis package provides a [PSR-3](https://www.php-fig.org/psr/psr-3/) compatible logging library. It is used extensively in the\n[Yii Framework](https://www.yiiframework.com/) but it can also be used as a separate package.\n\nThe logger sends or passes messages to multiple targets. Each target may filter these messages according to their severity level, and category, and then export them to some medium such as a file, an email or a syslog.\n\n## Requirements\n\n- PHP 8.0 or higher.\n\n## Installation\n\nThe package can be installed with [Composer](https://getcomposer.org):\n\n```shell\ncomposer require yiisoft/log\n```\n\n## General usage\n\nCreating a logger:\n\n```php\n/**\n * List of class instances that extend the \\Yiisoft\\Log\\Target abstract class.\n * \n * @var \\Yiisoft\\Log\\Target[] $targets\n */\n$logger = new \\Yiisoft\\Log\\Logger($targets);\n```\n\nWriting logs:\n\n```php\n$logger-\u003eemergency('Emergency message', ['key' =\u003e 'value']);\n$logger-\u003ealert('Alert message', ['key' =\u003e 'value']);\n$logger-\u003ecritical('Critical message', ['key' =\u003e 'value']);\n$logger-\u003ewarning('Warning message', ['key' =\u003e 'value']);\n$logger-\u003enotice('Notice message', ['key' =\u003e 'value']);\n$logger-\u003einfo('Info message', ['key' =\u003e 'value']);\n$logger-\u003edebug('Debug message', ['key' =\u003e 'value']);\n```\n\n### Message Flushing and Exporting\n\nLog messages are collected and stored in memory. To limit memory consumption, the logger will flush\nthe recorded messages to the log targets each time a certain number of log messages accumulate.\nYou can customize this number by calling the `\\Yiisoft\\Log\\Logger::setFlushInterval()` method:\n\n```php\n$logger-\u003esetFlushInterval(100); // default is 1000\n```\n\nEach log target also collects and stores messages in memory.\nMessage exporting in a target follows the same principle as in the logger.\nTo change the number of stored messages, call the `\\Yiisoft\\Log\\Target::setExportInterval()` method:\n\n```php\n$target-\u003esetExportInterval(100); // default is 1000\n```\n\n\u003e Note: All message flushing and exporting also occurs when the application ends.\n\n### Logging targets\n\nThis package contains two targets:\n\n- `Yiisoft\\Log\\PsrTarget` - passes log messages to another [PSR-3](https://www.php-fig.org/psr/psr-3/) compatible logger.\n- `Yiisoft\\Log\\StreamTarget` - writes log messages to the specified output stream.\n\nExtra logging targets are implemented as separate packages:\n\n- [Database](https://github.com/yiisoft/log-target-db)\n- [Email](https://github.com/yiisoft/log-target-email)\n- [File](https://github.com/yiisoft/log-target-file)\n- [Syslog](https://github.com/yiisoft/log-target-syslog)\n\n### Context providers\n\nContext providers are used to provide additional context data for log messages. You can define your own context provider\nin the `Logger` constructor:\n\n```php\n$logger = new \\Yiisoft\\Log\\Logger(contextProvider: $myContextProvider);\n```\n\nOut of the box, the following context providers are available:\n\n- `SystemContextProvider` — adds system information (time, memory usage, trace, default category);\n- `CommonContextProvider` — adds common data;\n- `CompositeContextProvider` — allows combining multiple context providers.\n\nBy default, the logger uses the built-in `SystemContextProvider`.\n\n#### `SystemContextProvider`\n\nThe `SystemContextProvider` adds the following data to the context:\n\n- `time` — current Unix timestamp with microseconds (float value);\n- `trace` — array of call stack information;\n- `memory` — memory usage in bytes.\n- `category` — category of the log message (always \"application\").\n\n`Yiisoft\\Log\\ContextProvider\\SystemContextProvider` constructor parameters:\n\n- `traceLevel` — how much call stack information (file name and line number) should be logged for each\n  log message. If the traceLevel is greater than 0, a similar number of call stacks will be logged at most. Note that only\n  application call stacks are counted.\n- `excludedTracePaths` — array of paths to exclude from tracing when tracing is enabled with `traceLevel`.\n\nAn example of custom parameters' usage:\n\n```php\n$logger = new \\Yiisoft\\Log\\Logger(\n    contextProvider: new Yiisoft\\Log\\ContextProvider\\SystemContextProvider(\n        traceLevel: 3,\n        excludedTracePaths: [\n            '/vendor/yiisoft/di',\n        ],\n    ),\n);\n```\n\n#### `CommonContextProvider`\n\nThe `CommonContextProvider` allows the adding of additional common information to the log context, for example:\n\n```php\n$logger = new \\Yiisoft\\Log\\Logger(\n    contextProvider: new Yiisoft\\Log\\ContextProvider\\CommonContextProvider([\n       'environment' =\u003e 'production',\n    ]),\n);\n```\n\n#### `CompositeContextProvider`\n\nThe `CompositeContextProvider` allows the combining of multiple context providers into one, for example:\n\n```php\n$logger = new \\Yiisoft\\Log\\Logger(\n    contextProvider: new Yiisoft\\Log\\ContextProvider\\CompositeContextProvider(\n        new Yiisoft\\Log\\ContextProvider\\SystemContextProvider(),\n        new Yiisoft\\Log\\ContextProvider\\CommonContextProvider(['environment' =\u003e 'production'])\n    ),\n);\n```\n\n## Documentation\n\n- [Yii guide to logging](https://github.com/yiisoft/docs/blob/master/guide/en/runtime/logging.md)\n- [Internals](docs/internals.md)\n\nIf you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is available.\nYou may also check out other [Yii Community Resources](https://www.yiiframework.com/community).\n\n## License\n\nThe Yii Logging Library is free software. It is released under the terms of the BSD License.\nPlease see [`LICENSE`](./LICENSE.md) for more information.\n\nMaintained by [Yii Software](https://www.yiiframework.com/).\n\n## Support the project\n\n[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective\u0026logoColor=7eadf1\u0026labelColor=555555)](https://opencollective.com/yiisoft)\n\n## Follow updates\n\n[![Official website](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](https://www.yiiframework.com/)\n[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter\u0026logoColor=1DA1F2\u0026labelColor=555555?style=flat)](https://twitter.com/yiiframework)\n[![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat\u0026logo=telegram)](https://t.me/yii3en)\n[![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat\u0026logo=facebook\u0026logoColor=ffffff)](https://www.facebook.com/groups/yiitalk)\n[![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat\u0026logo=slack)](https://yiiframework.com/go/slack)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Flog","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyiisoft%2Flog","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Flog/lists"}