├── Helper └── Data.php ├── LICENCE ├── Magento └── Framework │ ├── Cache │ └── InvalidateLogger.php │ └── Logger │ └── Handler │ ├── Debug.php │ ├── Exception.php │ └── System.php ├── Model └── Config │ └── Source │ └── LogLevel.php ├── README.md ├── composer.json ├── etc ├── adminhtml │ └── system.xml ├── di.xml └── module.xml └── registration.php /Helper/Data.php: -------------------------------------------------------------------------------- 1 | storeManager = $storeManager; 53 | parent::__construct($context); 54 | } 55 | 56 | /** 57 | * @param $field 58 | * @param null $storeId 59 | * @return mixed 60 | */ 61 | public function getConfigValue($field, $storeId = null) 62 | { 63 | return $this->scopeConfig->getValue( 64 | $field, ScopeInterface::SCOPE_STORE, $storeId 65 | ); 66 | } 67 | 68 | /** 69 | * @param $code 70 | * @param null $storeId 71 | * @return mixed 72 | */ 73 | public function getGeneralConfig($code, $storeId = null) 74 | { 75 | return $this->getConfigValue(self::XML_PATH_SRS . $code, $storeId); 76 | } 77 | 78 | public function canLog($logLevel = 200) 79 | { 80 | return ( ! $this->getGeneralConfig('enabled') || ($this->getGeneralConfig('enabled') && $logLevel >= $this->getGeneralConfig('log_level')) ); 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 JustBetter 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Magento/Framework/Cache/InvalidateLogger.php: -------------------------------------------------------------------------------- 1 | helper = $helper; 16 | parent::__construct($filesystem, $filePath, $fileName); 17 | } 18 | 19 | public function write(array $record) 20 | { 21 | if ($this->helper->canLog($record['level'])) { 22 | parent::write($record); 23 | } 24 | 25 | return; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Magento/Framework/Logger/Handler/Exception.php: -------------------------------------------------------------------------------- 1 | helper = $helper; 20 | parent::__construct($filesystem, $filePath, $fileName); 21 | } 22 | 23 | public function write(array $record) 24 | { 25 | if ($this->helper->canLog($record['level'])) { 26 | parent::write($record); 27 | } 28 | 29 | return; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Magento/Framework/Logger/Handler/System.php: -------------------------------------------------------------------------------- 1 | helper = $helper; 27 | parent::__construct($filesystem, $exceptionHandler, $filePath); 28 | } 29 | 30 | /** 31 | * Writes formatted record through the handler. 32 | * 33 | * @param $record array The record metadata 34 | * @return void 35 | */ 36 | public function write(array $record) 37 | { 38 | // catch all exceptions anyway 39 | if (isset($record['context']['exception'])) { 40 | $this->exceptionHandler->handle($record); 41 | 42 | return; 43 | } 44 | 45 | if ($this->helper->canLog($record['level'])) { 46 | $record['formatted'] = $this->getFormatter()->format($record); 47 | 48 | parent::write($record); 49 | } 50 | 51 | return; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Model/Config/Source/LogLevel.php: -------------------------------------------------------------------------------- 1 | Logger::DEBUG, 'label' => __('Debug')], 17 | ['value' => Logger::INFO, 'label' => __('Info')], 18 | ['value' => Logger::NOTICE, 'label' => __('Notice')], 19 | ['value' => Logger::WARNING, 'label' => __('Warning')], 20 | ['value' => Logger::CRITICAL, 'label' => __('Critical')], 21 | ['value' => Logger::ALERT, 'label' => __('Alert')], 22 | ['value' => Logger::ALERT, 'label' => __('Emergency')], 23 | ]; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Magento 2 Disable spam in log 2 | 3 | This Magento 2 module disables spam in the magento logs. 4 | 5 | ## Installation 6 | - `composer require justbetter/magento2-disable-spam-in-log` 7 | - `bin/magento module:enable JustBetter_DisableSpamInLog` 8 | - `bin/magento setup:upgrade && bin/magento setup:static-content:deploy` 9 | 10 | ## Configuration 11 | - Options for the module are defined in the backend under Stores > Configuration > JustBetter > Disable spam in log configuration. 12 | 13 | ## Compability 14 | The module is tested on magento version 2.2.x 15 | 16 | ## Ideas, bugs or suggestions? 17 | Please create a [issue](https://github.com/justbetter/magento2-disable-spam-in-log/issues) or a [pull request](https://github.com/justbetter/magento2-disable-spam-in-log/pulls). 18 | 19 | ## About us 20 | We’re a innovative development agency from The Netherlands building awesome websites, webshops and web applications with Laravel and Magento. Check out our website [justbetter.nl](https://justbetter.nl) and our [open source projects](https://github.com/justbetter). 21 | 22 | ## License 23 | [MIT](LICENSE) 24 | 25 | --- 26 | 27 | JustBetter logo 28 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "justbetter/magento2-disable-spam-in-log", 3 | "description": "Magento 2 disables log lines with certain log level", 4 | "type": "magento2-module", 5 | "version": "1.0.0", 6 | "license": "MIT", 7 | "require": { 8 | "php": ">=7.0", 9 | "magento/framework": "*" 10 | }, 11 | "authors": [ 12 | { 13 | "name": "Rakhal Imming", 14 | "email": "rakhal@justbetter.nl", 15 | "homepage": "https://justbetter.nl", 16 | "role": "Developer" 17 | } 18 | ], 19 | "autoload": { 20 | "psr-4": { "JustBetter\\DisableSpamInLog\\": "" }, 21 | "files": [ "registration.php" ] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /etc/adminhtml/system.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | separator-top 9 | 10 | justbetter 11 | JustBetter_DisableSpamInLog::configuration 12 | 13 | 14 | 15 | 16 | Magento\Config\Model\Config\Source\Yesno 17 | 18 | 19 | 20 | Minimum log level to log in all logs 21 | JustBetter\DisableSpamInLog\Model\Config\Source\LogLevel 22 | 23 | 24 |
25 |
26 |
27 | -------------------------------------------------------------------------------- /etc/di.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /etc/module.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /registration.php: -------------------------------------------------------------------------------- 1 |