PHP code example of phpro / mage2-module-logger-handler

1. Go to this page and download the library: Download phpro/mage2-module-logger-handler library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phpro / mage2-module-logger-handler example snippets


    
    namespace Vendor\Module\Config;
    
    use Phpro\LoggerHandler\Config\LogConfiguration;
    use Magento\Framework\App\Config\ScopeConfigInterface;
    
    class SystemConfiguration implements LogConfiguration
    {
        const XML_LOG_FILE_NAME = 'module/log_type/log_file_name';
        const XML_LOG_LEVEL = 'module/log_type/log_level';
        const LOG_DIR = 'var' . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR;
    
        /**
         * @var ScopeConfigInterface
         */
        private $config;
    
        public function __construct(ScopeConfigInterface $config)
        {
            $this->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.

    <!-- di.xml -->
    <?xml version="1.0"