{"id":20310134,"url":"https://github.com/phpro/phpro-mage2-module-logger-handler","last_synced_at":"2025-04-11T15:40:57.106Z","repository":{"id":40248651,"uuid":"275171720","full_name":"phpro/phpro-mage2-module-logger-handler","owner":"phpro","description":null,"archived":false,"fork":false,"pushed_at":"2022-05-18T08:44:38.000Z","size":16,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-25T11:49:21.548Z","etag":null,"topics":[],"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/phpro.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2020-06-26T14:12:13.000Z","updated_at":"2022-05-18T08:43:50.000Z","dependencies_parsed_at":"2022-08-24T13:20:38.206Z","dependency_job_id":null,"html_url":"https://github.com/phpro/phpro-mage2-module-logger-handler","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpro%2Fphpro-mage2-module-logger-handler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpro%2Fphpro-mage2-module-logger-handler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpro%2Fphpro-mage2-module-logger-handler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpro%2Fphpro-mage2-module-logger-handler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phpro","download_url":"https://codeload.github.com/phpro/phpro-mage2-module-logger-handler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248145752,"owners_count":21055198,"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":[],"created_at":"2024-11-14T17:30:06.183Z","updated_at":"2025-04-11T15:40:57.084Z","avatar_url":"https://github.com/phpro.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](https://github.com/phpro/phpro-mage2-module-logger-handler/workflows/.github/workflows/grumphp.yml/badge.svg)\n\n# Logger Handler for Magento 2\n\nThis module allows you to easily configure custom log files. Especially useful when building several integrations, each requiring a separate log file.\n\n## Installation\n\n`composer require phpro/mage2-module-logger-handler`\n\n## How to use\n\nThis module is only a basic building block. You can build on top of this to create custom log files in your projects. \nBelow you can find an example implementation.\n\n### Stores configuration\n\nTo use a custom log file, you can add the following to the system config. This module also provides a source model for the log levels.\n\n    \u003c!-- system.xml --\u003e\n    \u003c?xml version=\"1.0\"?\u003e\n    \u003cconfig xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n            xsi:noNamespaceSchemaLocation=\"urn:magento:module:Magento_Config:etc/system_file.xsd\"\u003e\n        \u003csystem\u003e\n            \u003csection id=\"module\" sortOrder=\"10\" showInDefault=\"1\" showInWebsite=\"1\" showInStore=\"1\"\u003e\n                \u003cgroup id=\"log_type\" translate=\"label\" sortOrder=\"20\" showInDefault=\"1\"\u003e\n                    \u003cfield id=\"log_file_name\" translate=\"label\" type=\"text\" sortOrder=\"10\" showInDefault=\"1\"\u003e\n                        \u003clabel\u003eLog File Name\u003c/label\u003e\n                    \u003c/field\u003e\n                    \u003cfield id=\"log_level\" translate=\"label\" type=\"select\" sortOrder=\"20\" showInDefault=\"1\"\u003e\n                        \u003clabel\u003eLog Level\u003c/label\u003e\n                        \u003csource_model\u003ePhpro\\LoggerHandler\\Config\\LogLevelsSource\u003c/source_model\u003e \u003c!-- Custom source model which is available in this module --\u003e\n                    \u003c/field\u003e\n                \u003c/group\u003e\n            \u003c/section\u003e\n        \u003c/system\u003e\n    \u003c/config\u003e\n\n\n### Configuration class\n\nYou will need to create a Configuration class which implements the LogConfiguration interface. This Configuration class will be used by the Logger Handler.\n\nThis is an example of a Configuration class which uses the stores configuration defined above.\n\n    \u003c?php\n    \n    namespace Vendor\\Module\\Config;\n    \n    use Phpro\\LoggerHandler\\Config\\LogConfiguration;\n    use Magento\\Framework\\App\\Config\\ScopeConfigInterface;\n    \n    class SystemConfiguration implements LogConfiguration\n    {\n        const XML_LOG_FILE_NAME = 'module/log_type/log_file_name';\n        const XML_LOG_LEVEL = 'module/log_type/log_level';\n        const LOG_DIR = 'var' . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR;\n    \n        /**\n         * @var ScopeConfigInterface\n         */\n        private $config;\n    \n        public function __construct(ScopeConfigInterface $config)\n        {\n            $this-\u003econfig = $config;\n        }\n    \n        /**\n         * This function should return the full path to the log file starting from the magento root\n         */\n        public function getLogFileName(): string\n        {\n            return self::LOG_DIR . $this-\u003econfig-\u003egetValue(self::XML_LOG_FILE_NAME);\n        }\n    \n        public function getLogLevel(): string\n        {\n            return $this-\u003econfig-\u003egetValue(self::XML_LOG_LEVEL);\n        }\n    }\n\n\n### Virtual Types\n\nYou will need to create the following Virtual Types to use a custom logger in a service class.\n\n    \u003c!-- di.xml --\u003e\n    \u003c?xml version=\"1.0\" ?\u003e\n    \u003cconfig xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n            xsi:noNamespaceSchemaLocation=\"urn:magento:framework:ObjectManager/etc/config.xsd\"\u003e\n        \u003cvirtualType name=\"[vendor_module_logtype]_logger_handler\" type=\"Phpro\\LoggerHandler\\Logger\\Handler\"\u003e\n            \u003carguments\u003e\n                \u003cargument name=\"config\" xsi:type=\"object\"\u003eVendor\\Module\\Config\\SystemConfiguration\u003c/argument\u003e \u003c!-- Configuration class created above --\u003e\n            \u003c/arguments\u003e\n        \u003c/virtualType\u003e\n        \u003cvirtualType name=\"[vendor_module_logtype]_logger\" type=\"Monolog\\Logger\"\u003e\n            \u003carguments\u003e\n                \u003cargument name=\"name\" xsi:type=\"string\"\u003e[module-logtype]-logger\u003c/argument\u003e \u003c!-- channel name; will also show in log files --\u003e\n                \u003cargument name=\"handlers\" xsi:type=\"array\"\u003e\n                    \u003citem name=\"stream\" xsi:type=\"object\"\u003e[vendor_module_logtype]_logger_handler\u003c/item\u003e \u003c!-- refers to the logger handler VirtualType --\u003e\n                \u003c/argument\u003e\n            \u003c/arguments\u003e\n        \u003c/virtualType\u003e\n        \n        \u003c!-- inject custom logger in service class --\u003e\n        \u003ctype name=\"Vendor\\Module\\Service\\DoSomething\"\u003e\n            \u003carguments\u003e\n                \u003cargument name=\"logger\" xsi:type=\"object\"\u003e[vendor_module_logtype]_logger\u003c/argument\u003e \u003c!-- refers to the logger VirtualType --\u003e\n            \u003c/arguments\u003e\n        \u003c/type\u003e\n    \u003c/config\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpro%2Fphpro-mage2-module-logger-handler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpro%2Fphpro-mage2-module-logger-handler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpro%2Fphpro-mage2-module-logger-handler/lists"}