From a9fb352fd91f5a7d876490b6302cfe70eec569ab Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Tue, 12 Jan 2021 09:15:03 +0200 Subject: [PATCH] log handler fix --- .../Espo/Core/Log/Handler/EspoFileHandler.php | 17 ++++++----------- .../Log/Handler/EspoRotatingFileHandler.php | 11 ++++++++--- application/Espo/Core/Log/LogLoader.php | 7 ++++--- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/application/Espo/Core/Log/Handler/EspoFileHandler.php b/application/Espo/Core/Log/Handler/EspoFileHandler.php index eb3e9cdd18..3868ca518f 100644 --- a/application/Espo/Core/Log/Handler/EspoFileHandler.php +++ b/application/Espo/Core/Log/Handler/EspoFileHandler.php @@ -34,7 +34,10 @@ use Monolog\{ Handler\StreamHandler as MonologStreamHandler, }; -use Espo\Core\Utils\File\Manager as FileManager; +use Espo\Core\{ + Utils\File\Manager as FileManager, + Utils\Config, +}; use LogicException; use UnexpectedValueException; @@ -45,19 +48,11 @@ class EspoFileHandler extends MonologStreamHandler protected $maxErrorMessageLength = 5000; - protected $configPath = 'data/config.php'; - - public function __construct(string $filename, $level = Logger::DEBUG, bool $bubble = true) + public function __construct(string $filename, $level = Logger::DEBUG, bool $bubble = true, Config $config) { parent::__construct($filename, $level, $bubble); - $defaultPermissions = null; - - if (file_exists($this->configPath)) { - $configData = include $this->configPath; - - $defaultPermissions = $configData['defaultPermissions'] ?? null; - } + $defaultPermissions = $config->get('defaultPermissions'); $this->fileManager = new FileManager($defaultPermissions); } diff --git a/application/Espo/Core/Log/Handler/EspoRotatingFileHandler.php b/application/Espo/Core/Log/Handler/EspoRotatingFileHandler.php index e8a89f2a7a..4570442946 100644 --- a/application/Espo/Core/Log/Handler/EspoRotatingFileHandler.php +++ b/application/Espo/Core/Log/Handler/EspoRotatingFileHandler.php @@ -31,6 +31,10 @@ namespace Espo\Core\Log\Handler; use Monolog\Logger; +use Espo\Core\{ + Utils\Config, +}; + class EspoRotatingFileHandler extends EspoFileHandler { protected $dateFormat = 'Y-m-d'; @@ -41,12 +45,13 @@ class EspoRotatingFileHandler extends EspoFileHandler protected $maxFiles; - public function __construct(string $filename, int $maxFiles = 0, $level = Logger::DEBUG, bool $bubble = true) - { + public function __construct( + string $filename, int $maxFiles = 0, $level = Logger::DEBUG, bool $bubble = true, Config $config + ) { $this->filename = $filename; $this->maxFiles = (int) $maxFiles; - parent::__construct($this->getTimedFilename(), $level, $bubble); + parent::__construct($this->getTimedFilename(), $level, $bubble, $config); $this->rotate(); } diff --git a/application/Espo/Core/Log/LogLoader.php b/application/Espo/Core/Log/LogLoader.php index fe234525e6..62b5f5c757 100644 --- a/application/Espo/Core/Log/LogLoader.php +++ b/application/Espo/Core/Log/LogLoader.php @@ -108,9 +108,10 @@ class LogLoader if ($rotation) { $maxFileNumber = $this->config->get('logger.maxFileNumber') ?? self::MAX_FILE_NUMBER; - $handler = new EspoRotatingFileHandler($path, $maxFileNumber, $levelCode); - } else { - $handler = new EspoFileHandler($path, $levelCode); + $handler = new EspoRotatingFileHandler($path, $maxFileNumber, $levelCode, true, $this->config); + } + else { + $handler = new EspoFileHandler($path, $levelCode, true, $this->config); } $formatter = new LineFormatter(