{"id":15029744,"url":"https://github.com/spacetab-io/logger-php","last_synced_at":"2025-04-09T20:32:53.937Z","repository":{"id":57056357,"uuid":"253290509","full_name":"spacetab-io/logger-php","owner":"spacetab-io","description":"Simple pre-configured non-blocking logging for PHP based on Amp and Monolog.","archived":false,"fork":false,"pushed_at":"2022-10-11T06:53:35.000Z","size":27,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-23T22:26:32.197Z","etag":null,"topics":["amphp","brackets","logs","monolog","php","php74","psr"],"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/spacetab-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-05T17:19:45.000Z","updated_at":"2025-03-05T20:13:49.000Z","dependencies_parsed_at":"2022-08-24T14:00:35.648Z","dependency_job_id":null,"html_url":"https://github.com/spacetab-io/logger-php","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacetab-io%2Flogger-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacetab-io%2Flogger-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacetab-io%2Flogger-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spacetab-io%2Flogger-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spacetab-io","download_url":"https://codeload.github.com/spacetab-io/logger-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248107726,"owners_count":21048988,"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":["amphp","brackets","logs","monolog","php","php74","psr"],"created_at":"2024-09-24T20:11:32.046Z","updated_at":"2025-04-09T20:32:53.884Z","avatar_url":"https://github.com/spacetab-io.png","language":"PHP","funding_links":[],"categories":["Logging"],"sub_categories":["Tunnel"],"readme":"Simple pre-configured Monolog wrapper\n-------------------------------------\n\n[![CircleCI](https://circleci.com/gh/spacetab-io/logger-php.svg?style=svg)](https://circleci.com/gh/spacetab-io/logger-php)\n[![codecov](https://codecov.io/gh/spacetab-io/logger-php/branch/master/graph/badge.svg)](https://codecov.io/gh/spacetab-io/logger-php)\n\nSince `2.0.0` logger is non-blocking and based on Amp and Monolog. \n\nI create this library with one target, — I'm sick of always copies \nand paste same code to any of my microservices with logs. \n\nThis wrapper solves one problem with logs. And this problem, — fucking brackets -\u003e [] [] [] [].\n\nExample, how this wrapper present the logs:\n\n```bash\n[2019-04-29 21:39:52] Server.INFO: CONFIG_PATH = ./configuration  \n[2019-04-29 21:39:52] Server.INFO: STAGE = local  \n[2019-04-29 21:39:52] Server.INFO: Configuration module loaded  \n[2019-04-29 21:39:52] Server.INFO: HTTP static server started at 0.0.0.0:8080  \n \n```\n\nThis is a normal view and without fucking brackets of Monolog's. Okay, I'm hate it too, how it uses?\n\n## Usage\n\n0) Install library through `composer`:\n\n```bash\ncomposer require spacetab-io/logger\n```\n\n1) Basic example for most cases will do like as:\n\n```php\nuse Spacetab\\Logger\\Logger;\n\n$log = Logger::default(); // Psr\\Log\\LoggerInterface\n$log-\u003einfo('write something');\n```\n\n2) If you want register this library thought Service Provider (add to application DI container), see this example:\n\nNote: this is a pseudocode for example.\n\n```php\nuse Monolog\\Logger;\nuse Psr\\Container\\ContainerInterface;\nuse Psr\\Log\\LoggerInterface;\n\nclass LoggerModule implements ServiceProvider\n{\n    /**\n     * @param ContainerInterface $container\n     */\n    public function provideServices($container): void\n    {\n        $container-\u003eregister(LoggerInterface::class, function () {\n            return Logger::default(); // it's all!\n        });\n    }\n}\n```\n\n3) How to register logger without static:: method?\nIt also very simple.\n\n```php\n\u003c?php\n\nuse Spacetab\\Logger\\Logger;\nuse Psr\\Log\\LogLevel;\n\n$log = new Logger('ChannelName', LogLevel::DEBUG); // enabled debug mode and set the channel name\n$log-\u003eaddStreamHandler();\n$log-\u003eregister();\n\n$log-\u003egetMonolog()-\u003einfo('Hello world');\n```\n\n4) Okay. It's cool. But I have written logs to multiple streams. How I do it?\n\n```php\n\u003c?php\nuse Spacetab\\Logger\\Logger;\nuse Monolog\\Handler\\HandlerInterface;\nuse Monolog\\Handler\\NullHandler;\nuse Psr\\Log\\LogLevel;\n\n$log = new Logger('ChannelName', LogLevel::DEBUG); // enabled debug mode and set the channel name\n$log-\u003eaddStreamHandler();\n$log-\u003eaddHandler(function (string $level): HandlerInterface {\n    return new NullHandler($level);\n});\n\n$log-\u003eregister();\n\n$log-\u003egetMonolog()-\u003einfo('Diligence is the mother of success');\n```\n\nSimple? Yes, and without fucking brackets.\n\n## License\n\nThe MIT License\n\nCopyright © 2022 spacetab.io, Inc. https://spacetab.io\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspacetab-io%2Flogger-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspacetab-io%2Flogger-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspacetab-io%2Flogger-php/lists"}