don't use logger factory, logger should configured outside and injected in it
This commit is contained in:
parent
1d8fd1459a
commit
c76428b1c8
@ -19,8 +19,7 @@
|
||||
],
|
||||
"require": {
|
||||
"guzzlehttp/guzzle": "^7.0",
|
||||
"d3/sensitive-message-formatter": "^1.0",
|
||||
"d3/logger-factory": "^1.0"
|
||||
"d3/sensitive-message-formatter": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^10.5",
|
||||
|
@ -1,83 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*
|
||||
* https://www.d3data.de
|
||||
*
|
||||
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
||||
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
||||
* @link https://www.oxidmodule.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace D3\GuzzleFactory\Apps;
|
||||
|
||||
use D3\LoggerFactory\LoggerFactory;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use Monolog\Logger;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use RuntimeException;
|
||||
|
||||
trait OxidLoggerTrait
|
||||
{
|
||||
public function addOxidLogger(): void
|
||||
{
|
||||
if (!class_exists(Registry::class)) {
|
||||
throw new RuntimeException(__METHOD__.' can executed in OXID eShop installations only');
|
||||
}
|
||||
|
||||
$this->loggers['oxid'] = Registry::getLogger();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $loggerName
|
||||
* @param string $filePath
|
||||
* @param int $logLevel
|
||||
* @param int|null $maxFiles
|
||||
* @param array<int|string, string|array<string, string|int>> $specialHandlers
|
||||
*
|
||||
* @return void
|
||||
* @throws InvalidArgumentException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addCombinedOxidAndFileLogger(
|
||||
string $loggerName,
|
||||
string $filePath,
|
||||
int $logLevel = Logger::INFO,
|
||||
?int $maxFiles = null,
|
||||
array $specialHandlers = []
|
||||
): void {
|
||||
if (isset($this->loggers['oxid'])) {
|
||||
unset($this->loggers['oxid']);
|
||||
}
|
||||
|
||||
$this->loggers[$loggerName] = $this->getLoggerFactory()->getCombinedOxidAndFileLogger(
|
||||
$loggerName,
|
||||
$filePath,
|
||||
$logLevel,
|
||||
$maxFiles,
|
||||
/** @phpstan-ignore argument.type */
|
||||
$specialHandlers
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use LoggerFactory::getOxidLogPath
|
||||
* @param string $fileName
|
||||
* @return string
|
||||
*/
|
||||
public function getOxidLogPath(string $fileName): string
|
||||
{
|
||||
if (!class_exists(Registry::class)) {
|
||||
throw new RuntimeException(__METHOD__.' can executed in OXID eShop installations only');
|
||||
}
|
||||
|
||||
return OX_BASE_PATH . '/log' . DIRECTORY_SEPARATOR . $fileName;
|
||||
}
|
||||
}
|
@ -17,66 +17,15 @@ declare(strict_types=1);
|
||||
|
||||
namespace D3\GuzzleFactory;
|
||||
|
||||
use D3\GuzzleFactory\Apps\OxidLoggerTrait;
|
||||
use D3\LoggerFactory\LoggerFactory;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use Monolog\Handler\AbstractProcessingHandler;
|
||||
use Monolog\Logger;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
trait LoggerTrait
|
||||
{
|
||||
use OxidLoggerTrait;
|
||||
|
||||
/** @var LoggerInterface[] */
|
||||
protected array $loggers = [];
|
||||
protected ?int $messageLevel = null;
|
||||
|
||||
protected function getLoggerFactory(): LoggerFactory
|
||||
{
|
||||
return LoggerFactory::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $loggerName
|
||||
* @param string $filePath
|
||||
* @param int $logLevel
|
||||
* @param int|null $maxFiles
|
||||
* @param array<int|string, string|array<string, string|int>> $specialHandlers
|
||||
*
|
||||
* @return void
|
||||
* @throws InvalidArgumentException
|
||||
* @throws Exception
|
||||
*/
|
||||
public function addFileLogger(
|
||||
string $loggerName,
|
||||
string $filePath,
|
||||
int $logLevel = Logger::INFO,
|
||||
?int $maxFiles = null,
|
||||
array $specialHandlers = [] // see LoggerFactory constants
|
||||
): void {
|
||||
$this->loggers[$loggerName] = $this->getLoggerFactory()
|
||||
/** @phpstan-ignore argument.type */
|
||||
->getFileLogger($loggerName, $filePath, $logLevel, $maxFiles, $specialHandlers);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use LoggerFactory::getFileLoggerStreamHandler
|
||||
* @param string $filePath
|
||||
* @param int $logLevel
|
||||
* @param int|null $maxFiles
|
||||
* @return AbstractProcessingHandler
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getFileLoggerStreamHandler(
|
||||
string $filePath,
|
||||
int $logLevel = Logger::INFO,
|
||||
?int $maxFiles = null
|
||||
): AbstractProcessingHandler {
|
||||
return $this->getLoggerFactory()->getFileLoggerStreamHandler($filePath, $logLevel, $maxFiles);
|
||||
}
|
||||
|
||||
public function addConfiguredLogger(LoggerInterface $logger): void
|
||||
{
|
||||
$this->loggers[md5(serialize($logger))] = $logger;
|
||||
|
Loading…
x
Reference in New Issue
Block a user