add combined (OXID + custom) logger
This commit is contained in:
@ -17,6 +17,10 @@ declare(strict_types=1);
|
||||
|
||||
namespace D3\GuzzleFactory\Apps;
|
||||
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Logger;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use RuntimeException;
|
||||
|
||||
@ -31,6 +35,36 @@ trait OxidLoggerTrait
|
||||
$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
|
||||
{
|
||||
if (!class_exists(Registry::class)) {
|
||||
|
Reference in New Issue
Block a user