An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

![](https://github.com/phpro/phpro-mage2-module-logger-handler/workflows/.github/workflows/grumphp.yml/badge.svg)

# 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