{"id":14966476,"url":"https://github.com/beter-co/yii2-beter-logging","last_synced_at":"2025-07-27T07:07:50.186Z","repository":{"id":47229291,"uuid":"494999232","full_name":"BETER-CO/yii2-beter-logging","owner":"BETER-CO","description":"yii2-beter-logging: Bulletproof logging for enterprise yii2 projects.","archived":false,"fork":false,"pushed_at":"2024-01-25T17:52:11.000Z","size":633,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-16T18:45:08.318Z","etag":null,"topics":["log","logger","logging","logstash","monolog","yii","yii-monolog","yii2","yii2-extension","yii2-logger","yii2-logstash","yii2-monolog"],"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/BETER-CO.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2022-05-22T08:16:35.000Z","updated_at":"2024-07-26T20:26:03.000Z","dependencies_parsed_at":"2024-09-14T02:54:28.651Z","dependency_job_id":null,"html_url":"https://github.com/BETER-CO/yii2-beter-logging","commit_stats":{"total_commits":43,"total_committers":2,"mean_commits":21.5,"dds":"0.023255813953488413","last_synced_commit":"22b580684b1e3a561a24b7c7468078be9264bf0b"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/BETER-CO/yii2-beter-logging","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BETER-CO%2Fyii2-beter-logging","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BETER-CO%2Fyii2-beter-logging/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BETER-CO%2Fyii2-beter-logging/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BETER-CO%2Fyii2-beter-logging/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BETER-CO","download_url":"https://codeload.github.com/BETER-CO/yii2-beter-logging/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BETER-CO%2Fyii2-beter-logging/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267320257,"owners_count":24068527,"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-07-27T02:00:11.917Z","response_time":82,"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":["log","logger","logging","logstash","monolog","yii","yii-monolog","yii2","yii2-extension","yii2-logger","yii2-logstash","yii2-monolog"],"created_at":"2024-09-24T13:36:26.551Z","updated_at":"2025-07-27T07:07:50.122Z","avatar_url":"https://github.com/BETER-CO.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yii2-beter-logging\n\nBulletproof logging for enterprise yii2 projects.\n\nmonolog 2.x integration, custom LogTarget with delayed queue, pretty console handler, logstash via udp and tcp with deep yii2 integration.\n\n![CLI colors](https://raw.githubusercontent.com/BETER-CO/yii2-beter-logging/master/doc/assets/cli_colors.jpg)\n\nFeatures:\n* uses monolog under the hood;\n* implements custom [log Target](https://www.yiiframework.com/doc/api/2.0/yii-log-target) to pass log entries to monolog;\n* allows handlers chaining if logstash handler fails, so no more loses of log entries;\n* allows tracking statistics of log handlers;\n* adds [log context](doc/logging-with-context.md) for messages and exceptions;\n* doesn't turn off the whole log Target on errors;\n* allows switching off handlers if they fail specific amount of times;\n* supports stdout/stderr with colors;\n* supports logstash tcp and udp transport;\n* native support of yii log features.\n\nRelated packages you need to try:\n* [beter/exception-with-context](https://packagist.org/packages/beter/exception-with-context) is used by\n`yii2-beter-logging` package to bring support of context data storing in the exception.\n[Check the doc](doc/logging-with-context.md).\n* [yii2-log-request-response](https://packagist.org/packages/beter/yii2-log-request-response) package contains\ncomponent the component that logs user info, request related info, headers, execution time and so on for requests\nand response in CLI scripts and WEB.\n\n## Installation\n\nThe preferred way to install this extension is through [composer](https://getcomposer.org/).\n\nEither run\n\n```\ncomposer require beter/yii2-beter-logging\n```\n\nor add\n\n```\n\"beter/yii2-beter-logging\": \"~1.0.0\" // add the latest version\n```\n\nto the require section of your composer.json.\n\n## Configuration\n\nTo use this extension, you have to configure it in your application configuration.\n\n### Configure Yii2 log component\n\nAdd `Beter\\Yii2\\Logging\\ProxyLogTarget` class to the list of your log Targets\n\n```\n'log' =\u003e [\n    'traceLevel' =\u003e YII_DEBUG ? 3 : 0,\n    'flushInterval' =\u003e 1,\n    'targets' =\u003e [\n        // other log targets\n\n        'monolog-proxy' =\u003e [\n            'class' =\u003e Beter\\Yii2\\Logging\\ProxyLogTarget::class,\n            'targetLogComponent' =\u003e [\n                'componentName' =\u003e 'monolog',\n                'logChannel' =\u003e 'main'\n            ],\n            'exportInterval' =\u003e 1,\n            'categories' =\u003e [],\n            'except' =\u003e [\n                'yii\\web\\UrlManager::parseRequest',\n                'yii\\web\\UrlRule::parseRequest',\n            ],\n            'levels' =\u003e ['error', 'warning', 'info', 'trace'],\n        ],\n\n        // other log targets\n    ],\n]\n```\n\n`ProxyLogTarget` extends [yii\\log\\Target](https://www.yiiframework.com/doc/api/2.0/yii-log-target) and supports\nall settings that yii\\log\\Target has, but with limitations:\n* `exportInterval` must be 1. `yii2-beter-logging` always resets this setting to 1 and notifies about this. See\n[details](#further-reading).\n* `logVars`, `maskVars` and `prefix` settings will be ignored and will be reset to empty arrays and null values.\nSee [details](#further-reading).\n\nThe only additional setting is `targetLogComponent` section. This is not standard setting for yii2 log Target.\nThis section is mandatory and it connects `Beter\\Yii2\\Logging\\ProxyLogTarget` with\n`Beter\\Yii2\\Logging\\MonologComponent`.\n\n`Beter\\Yii2\\Logging\\MonologComponent` may be configured with few monolog channels, but `ProxyLogTarget`\nrequires to specify the only one.\n\n\u003e If you need more monolog channels you may setup few `ProxyLogTarget`'s.\n\nCheck further doc sections for more details.\n\n### Configure MonologComponent\n\nLog Target passes log entries to `Beter\\Yii2\\Logging\\MonologComponent` and then\n`Beter\\Yii2\\Logging\\MonologComponent` passes them to\n[`Monolog\\Logger`](https://github.com/Seldaek/monolog/blob/2.x/doc/01-usage.md).\n\n`Beter\\Yii2\\Logging\\MonologComponent` configures custom handlers shipped with `yii2-beter-logging`. \n\nThe list of handlers supported:\n* `logstash`\n* `standard_stream`\n* `firephp`\n\nSo, configure `Beter\\Yii2\\Logging\\MonologComponent` class. Don't forget to use *the same name of\nthe component and monolog channel name* as was specified in `targetLogComponent` setting of the\n`Beter\\Yii2\\Logging\\ProxyLogTarget` (`\"monolog\"` and `\"main\"` in this example).\n\n```\n'monolog' =\u003e [\n    'class' =\u003e Beter\\Yii2\\Logging\\MonologComponent::class,\n    'channels' =\u003e [\n        'main' =\u003e [\n            'handler' =\u003e [\n                [\n                    'name' =\u003e 'logstash',\n                    'label' =\u003e 'logstash',\n                    'level' =\u003e 'debug',\n                    'bubble' =\u003e true,\n                    'host' =\u003e '1.2.3.4', // or host.address.com\n                    'port' =\u003e 5045,\n                    'socket_transport' =\u003e 'tcp',\n                    'persistent' =\u003e false,\n                    'socket_timeout' =\u003e 1,\n                    'writing_timeout' =\u003e 1,\n                    'connection_timeout' =\u003e 1,\n                    'max_handle_errors_before_disabling' =\u003e 3,\n                    'formatter' =\u003e [\n                        'name' =\u003e 'logstash',\n                        'trace_depth' =\u003e 10,\n                    ]\n                ],\n                [\n                    'name' =\u003e 'standard_stream',\n                    'stream' =\u003e 'php://stderr',\n                    'level' =\u003e 'debug',\n                    'bubble' =\u003e true,\n                    'formatter' =\u003e [\n                        'name' =\u003e 'console',\n                        'colorize' =\u003e true,\n                        'indentSize' =\u003e 2,\n                        'trace_depth' =\u003e 10,\n                    ]\n                ],\n                [\n                    'name' =\u003e 'firephp',\n                    'bubble' =\u003e false,\n                    'formatter' =\u003e [\n                        'name' =\u003e 'wildfire',\n                    ]\n                ],\n            ],\n            'processor' =\u003e [\n                [\n                    'name' =\u003e 'basic_processor',\n                    'env' =\u003e YII_ENV, // dev, prod, etc\n                    'app' =\u003e 'myapp',\n                    'service' =\u003e 'api',\n                    'exec_type' =\u003e 'web', // or cli, or etc\n                    'host' =\u003e gethostname(), // or set it as you want\n                ],\n                [\n                    'name' =\u003e 'correlation_id_processor',\n                    'length' =\u003e 32,\n                    'search_in_headers' =\u003e true, // true if not set explicitly\n                    'header_name' =\u003e 'X-Request-Id', // 'X-Request-Id' if not set explicitly\n                ],\n            ],\n        ],\n    ],\n],\n```\n\n### Configure boostrap order\n\nTo not lose any log entries you need to\n[boostrap](https://www.yiiframework.com/doc/guide/2.0/en/structure-applications#bootstrap)\n`Beter\\Yii2\\Logging\\MonologComponent` before any other component. `log` component must be the second component\nin the list.\n\n```\n// other settings\n\n'bootstrap' =\u003e [\n    'monolog',\n    'log',\n    'authManager',\n    // other components\n],\n\n// other settings\n```\n\n### Other configurations\n\nDon't forget to configure all your environments like `cli` and so on.\n\n\n## Usage\n\nJust use `log` component and `Yii::log()`-related methods as usual\n\n```\nYii::error('Error here', 'application'); // application is a category name\nor\nYii::info('Info here', __METHOD__); // if you call from method\n```\n\n## Further reading\n\n* [Development and testing](doc/development-and-testing.md)\n* [Logging in CLI](doc/logging-in-cli.md)\n* [Logging with a context](doc/logging-with-context.md)\n\nTBD:\n- Handlers, Formatters and Processors\n- Delayed errors\n- Extending\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeter-co%2Fyii2-beter-logging","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbeter-co%2Fyii2-beter-logging","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbeter-co%2Fyii2-beter-logging/lists"}