log handler fix

This commit is contained in:
Yuri Kuznetsov
2021-01-12 09:15:03 +02:00
parent dd2434d4b4
commit a9fb352fd9
3 changed files with 18 additions and 17 deletions

View File

@@ -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);
}

View File

@@ -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();
}

View File

@@ -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(