Compare commits
No commits in common. "1.1.0" and "1.0.0" have entirely different histories.
@ -4,13 +4,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
## [Unreleased](https://git.d3data.de/D3Public/guzzleFactory/compare/1.1.0...rel_1.x)
|
## [Unreleased](https://git.d3data.de/D3Public/guzzleFactory/compare/1.0.0...rel_1.x)
|
||||||
|
|
||||||
## [1.1.0](https://git.d3data.de/D3Public/guzzleFactory/compare/1.0.0...1.1.0) - 2025-01-27
|
|
||||||
### Added
|
|
||||||
- combined OXID logger and file logger
|
|
||||||
- errors are written here (expected behaviour)
|
|
||||||
- all error level are written to custom log file
|
|
||||||
|
|
||||||
## [1.0.0](https://git.d3data.de/D3Public/guzzleFactory/releases/tag/1.0.0) - 2025-01-01
|
## [1.0.0](https://git.d3data.de/D3Public/guzzleFactory/releases/tag/1.0.0) - 2025-01-01
|
||||||
### Added
|
### Added
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||

|
|
||||||
[](https://packagist.org/packages/d3/guzzle-factory)
|
|
||||||
[](https://git.d3data.de/D3Public/guzzleFactory/src/branch/main/LICENSE.md)
|
|
||||||
|
|
||||||
# Guzzle Factory
|
# Guzzle Factory
|
||||||
|
|
||||||
Guzzle factory for everyday simple configuration
|
Guzzle factory for everyday simple configuration
|
||||||
@ -22,7 +18,6 @@ $guzzleFactory->setMessageFormatter(
|
|||||||
'{method} {uri} HTTP/{version} {req_body}'.PHP_EOL.'RESPONSE: {code} - {res_body}',
|
'{method} {uri} HTTP/{version} {req_body}'.PHP_EOL.'RESPONSE: {code} - {res_body}',
|
||||||
['myUsername', 'myPassword']
|
['myUsername', 'myPassword']
|
||||||
);
|
);
|
||||||
$guzzleFactory->setMessageLevel(Logger::INFO);
|
|
||||||
$httpClient = $guzzleFactory->getGuzzle('https://remoteApi.com');
|
$httpClient = $guzzleFactory->getGuzzle('https://remoteApi.com');
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -39,7 +39,6 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "./vendor/bin/phpunit --no-coverage",
|
"test": "./vendor/bin/phpunit --no-coverage",
|
||||||
"test-coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html=coverage",
|
|
||||||
"check-style": "./vendor/bin/php-cs-fixer fix --verbose --dry-run",
|
"check-style": "./vendor/bin/php-cs-fixer fix --verbose --dry-run",
|
||||||
"fix-style": "./vendor/bin/php-cs-fixer fix --verbose",
|
"fix-style": "./vendor/bin/php-cs-fixer fix --verbose",
|
||||||
"check-code": "./vendor/bin/phpstan analyse -c phpstan.neon --no-progress --ansi"
|
"check-code": "./vendor/bin/phpstan analyse -c phpstan.neon --no-progress --ansi"
|
||||||
|
@ -17,10 +17,6 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace D3\GuzzleFactory\Apps;
|
namespace D3\GuzzleFactory\Apps;
|
||||||
|
|
||||||
use Exception;
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use Monolog\Handler\StreamHandler;
|
|
||||||
use Monolog\Logger;
|
|
||||||
use OxidEsales\Eshop\Core\Registry;
|
use OxidEsales\Eshop\Core\Registry;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
|
|
||||||
@ -35,36 +31,6 @@ trait OxidLoggerTrait
|
|||||||
$this->loggers['oxid'] = Registry::getLogger();
|
$this->loggers['oxid'] = Registry::getLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws Exception
|
|
||||||
* @throws InvalidArgumentException
|
|
||||||
*/
|
|
||||||
public function addCombinedOxidAndFileLogger(
|
|
||||||
string $loggerName,
|
|
||||||
string $filePath,
|
|
||||||
int $logLevel = Logger::INFO,
|
|
||||||
?int $maxFiles = null
|
|
||||||
): void
|
|
||||||
{
|
|
||||||
if (!class_exists(Registry::class)) {
|
|
||||||
throw new RuntimeException(__METHOD__.' can executed in OXID eShop installations only');
|
|
||||||
}
|
|
||||||
|
|
||||||
$logger = new Logger($loggerName);
|
|
||||||
$stream_handler = $this->getFileLoggerStreamHandler($filePath, $logLevel, $maxFiles);
|
|
||||||
$logger->pushHandler($stream_handler);
|
|
||||||
|
|
||||||
$oxidLogFilePath = $this->getOxidLogPath('oxideshop.log');
|
|
||||||
$oxidStreamHandler = new StreamHandler($oxidLogFilePath, Logger::ERROR);
|
|
||||||
$logger->pushHandler($oxidStreamHandler);
|
|
||||||
|
|
||||||
if (isset($this->loggers['oxid'])) {
|
|
||||||
unset($this->loggers['oxid']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->loggers[$loggerName] = $logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getOxidLogPath(string $fileName): string
|
public function getOxidLogPath(string $fileName): string
|
||||||
{
|
{
|
||||||
if (!class_exists(Registry::class)) {
|
if (!class_exists(Registry::class)) {
|
||||||
|
@ -20,7 +20,6 @@ namespace D3\GuzzleFactory;
|
|||||||
use D3\GuzzleFactory\Apps\OxidLoggerTrait;
|
use D3\GuzzleFactory\Apps\OxidLoggerTrait;
|
||||||
use Exception;
|
use Exception;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Monolog\Handler\AbstractProcessingHandler;
|
|
||||||
use Monolog\Handler\RotatingFileHandler;
|
use Monolog\Handler\RotatingFileHandler;
|
||||||
use Monolog\Handler\StreamHandler;
|
use Monolog\Handler\StreamHandler;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
@ -38,38 +37,17 @@ trait LoggerTrait
|
|||||||
* @throws Exception
|
* @throws Exception
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function addFileLogger(
|
public function addFileLogger(string $loggerName, string $filePath, int $logLevel = Logger::INFO, ?int $maxFiles = null): void
|
||||||
string $loggerName,
|
|
||||||
string $filePath,
|
|
||||||
int $logLevel = Logger::INFO,
|
|
||||||
?int $maxFiles = null
|
|
||||||
): void
|
|
||||||
{
|
{
|
||||||
$logger = new Logger($loggerName);
|
$logger = new Logger($loggerName);
|
||||||
$stream_handler = $this->getFileLoggerStreamHandler($filePath, $logLevel, $maxFiles);
|
$stream_handler = is_null($maxFiles) ?
|
||||||
|
new StreamHandler($filePath, $logLevel) :
|
||||||
|
new RotatingFileHandler($filePath, $maxFiles, $logLevel);
|
||||||
$logger->pushHandler($stream_handler);
|
$logger->pushHandler($stream_handler);
|
||||||
|
|
||||||
$this->loggers[$loggerName] = $logger;
|
$this->loggers[$loggerName] = $logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @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 is_null($maxFiles) ?
|
|
||||||
new StreamHandler($filePath, $logLevel) :
|
|
||||||
new RotatingFileHandler($filePath, $maxFiles, $logLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addConfiguredLogger(LoggerInterface $logger): void
|
public function addConfiguredLogger(LoggerInterface $logger): void
|
||||||
{
|
{
|
||||||
$this->loggers[md5(serialize($logger))] = $logger;
|
$this->loggers[md5(serialize($logger))] = $logger;
|
||||||
|
@ -40,25 +40,6 @@ trait OxidLoggerTestTrait
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
* @return void
|
|
||||||
* @throws ReflectionException
|
|
||||||
* @covers \D3\GuzzleFactory\GuzzleFactory::addCombinedOxidAndFileLogger
|
|
||||||
*/
|
|
||||||
public function testAddCombinedOxidAndFileLoggerWithoutOxid(): void
|
|
||||||
{
|
|
||||||
$sut = GuzzleFactory::create();
|
|
||||||
|
|
||||||
$this->expectException(RuntimeException::class);
|
|
||||||
|
|
||||||
$this->callMethod(
|
|
||||||
$sut,
|
|
||||||
'addCombinedOxidAndFileLogger',
|
|
||||||
['nameFixture', 'file/path.log', 1, 5]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @return void
|
* @return void
|
||||||
@ -103,32 +84,6 @@ trait OxidLoggerTestTrait
|
|||||||
$this->assertInstanceOf(Logger::class, $loggers['oxid']);
|
$this->assertInstanceOf(Logger::class, $loggers['oxid']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @test
|
|
||||||
* @return void
|
|
||||||
* @throws ReflectionException
|
|
||||||
* @covers \D3\GuzzleFactory\GuzzleFactory::addCombinedOxidAndFileLogger
|
|
||||||
*/
|
|
||||||
public function testAddCombinedOxidAndFileLoggerInOxid(): void
|
|
||||||
{
|
|
||||||
require_once __DIR__.'/../Helpers/classAliases.php';
|
|
||||||
|
|
||||||
$sut = GuzzleFactory::create();
|
|
||||||
|
|
||||||
$this->setValue($sut, 'loggers', ['oxid' => 1]);
|
|
||||||
|
|
||||||
$this->callMethod(
|
|
||||||
$sut,
|
|
||||||
'addCombinedOxidAndFileLogger',
|
|
||||||
['nameFixture', 'file/path.log', 1, 5]
|
|
||||||
);
|
|
||||||
|
|
||||||
$loggers = $this->getValue($sut, 'loggers');
|
|
||||||
$this->assertArrayHasKey('nameFixture', $loggers);
|
|
||||||
$this->assertArrayNotHasKey('oxid', $loggers);
|
|
||||||
$this->assertInstanceOf(Logger::class, $loggers['nameFixture']);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
* @return void
|
* @return void
|
||||||
|
@ -28,7 +28,6 @@ trait LoggerTestTrait
|
|||||||
* @test
|
* @test
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @covers \D3\GuzzleFactory\GuzzleFactory::addFileLogger
|
* @covers \D3\GuzzleFactory\GuzzleFactory::addFileLogger
|
||||||
* @covers \D3\GuzzleFactory\GuzzleFactory::getFileLoggerStreamHandler
|
|
||||||
* @dataProvider addFileLoggerDataProvider
|
* @dataProvider addFileLoggerDataProvider
|
||||||
*/
|
*/
|
||||||
public function testAddFileLogger(int $logLevel, ?int $maxFiles, string $expectedHandlerClass): void
|
public function testAddFileLogger(int $logLevel, ?int $maxFiles, string $expectedHandlerClass): void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user