https://github.com/phpro/phpro-mage2-module-logger-handler
https://github.com/phpro/phpro-mage2-module-logger-handler
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/phpro/phpro-mage2-module-logger-handler
- Owner: phpro
- License: mit
- Created: 2020-06-26T14:12:13.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-05-18T08:44:38.000Z (about 4 years ago)
- Last Synced: 2025-03-25T11:49:21.548Z (over 1 year ago)
- Language: PHP
- Size: 15.6 KB
- Stars: 1
- Watchers: 7
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README

# Logger Handler for Magento 2
This module allows you to easily configure custom log files. Especially useful when building several integrations, each requiring a separate log file.
## Installation
`composer require phpro/mage2-module-logger-handler`
## How to use
This module is only a basic building block. You can build on top of this to create custom log files in your projects.
Below you can find an example implementation.
### Stores configuration
To 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.
Log File Name
Log Level
Phpro\LoggerHandler\Config\LogLevelsSource
### Configuration class
You will need to create a Configuration class which implements the LogConfiguration interface. This Configuration class will be used by the Logger Handler.
This is an example of a Configuration class which uses the stores configuration defined above.
config = $config;
}
/**
* This function should return the full path to the log file starting from the magento root
*/
public function getLogFileName(): string
{
return self::LOG_DIR . $this->config->getValue(self::XML_LOG_FILE_NAME);
}
public function getLogLevel(): string
{
return $this->config->getValue(self::XML_LOG_LEVEL);
}
}
### Virtual Types
You will need to create the following Virtual Types to use a custom logger in a service class.
Vendor\Module\Config\SystemConfiguration
[module-logtype]-logger
[vendor_module_logtype]_logger_handler
[vendor_module_logtype]_logger