Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFWEB-2840: Introduce improve logging #464

Merged
merged 2 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog
## Unreleased
### Add
- Add campaigns to category view page
- Improve logging system

## [v4.2.1] - 2023.09.25
### Fix
- Fix problem with ssr/record-list.phtml template

## [v4.2.0] - 2023.09.18
Expand Down
10 changes: 9 additions & 1 deletion src/Controller/Adminhtml/TestConnection/TestConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Omikron\FactFinder\Communication\Client\ClientBuilder;
use Omikron\FactFinder\Communication\Credentials;
use Omikron\FactFinder\Communication\Resource\AdapterFactory;
use Omikron\Factfinder\Logger\FactFinderLogger;
use Omikron\Factfinder\Model\Api\CredentialsFactory;
use Omikron\Factfinder\Model\Config\AuthConfig;
use Psr\Http\Client\ClientExceptionInterface;
Expand All @@ -21,19 +22,22 @@ class TestConnection extends Action
private CredentialsFactory $credentialsFactory;
private AuthConfig $authConfig;
private ClientBuilder $clientBuilder;
private FactFinderLogger $logger;

public function __construct(
Action\Context $context,
JsonFactory $jsonResultFactory,
CredentialsFactory $credentialsFactory,
AuthConfig $authConfig,
ClientBuilder $clientBuilder
ClientBuilder $clientBuilder,
FactFinderLogger $logger
) {
parent::__construct($context);
$this->jsonResultFactory = $jsonResultFactory;
$this->credentialsFactory = $credentialsFactory;
$this->authConfig = $authConfig;
$this->clientBuilder = $clientBuilder;
$this->logger = $logger;
}

public function execute()
Expand All @@ -54,6 +58,10 @@ public function execute()

$message = new Phrase('Connection successfully established.');
} catch (ClientExceptionInterface $e) {
$this->logger->error(new Phrase(
'FACT-Finder response exception: %1, thrown at %2',
[$e->getMessage(), $e->getTraceAsString()]
));
$message = $e->getMessage();
}

Expand Down
10 changes: 9 additions & 1 deletion src/Controller/Adminhtml/TestConnection/TestFtpConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Magento\Backend\App\Action;
use Magento\Framework\Controller\Result\JsonFactory;
use Magento\Framework\Phrase;
use Omikron\Factfinder\Logger\FactFinderLogger;
use Omikron\Factfinder\Model\Config\FtpConfig;
use Omikron\Factfinder\Model\FtpUploader;

Expand All @@ -16,17 +17,20 @@ class TestFtpConnection extends Action
private JsonFactory $jsonResultFactory;
private FtpUploader $ftpUploader;
private FtpConfig $ftpConfig;
private FactFinderLogger $logger;

public function __construct(
Action\Context $context,
JsonFactory $jsonResultFactory,
FtpUploader $ftpUploader,
FtpConfig $ftpConfig
FtpConfig $ftpConfig,
FactFinderLogger $logger
) {
parent::__construct($context);
$this->jsonResultFactory = $jsonResultFactory;
$this->ftpUploader = $ftpUploader;
$this->ftpConfig = $ftpConfig;
$this->logger = $logger;
}

public function execute()
Expand All @@ -38,6 +42,10 @@ public function execute()
$params = $this->getConfig($this->getRealValuesFromObscured($request->getParams())) + $this->ftpConfig->toArray();
$this->ftpUploader->testConnection($params);
} catch (\Exception $e) {
$this->logger->error(new Phrase(
'FACT-Finder FTP exception: %1, thrown at %2',
[$e->getMessage(), $e->getTraceAsString()]
));
$message = $e->getMessage();
}

Expand Down
9 changes: 9 additions & 0 deletions src/Logger/FactFinderLogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

declare(strict_types=1);

namespace Omikron\Factfinder\Logger;

class FactFinderLogger extends \Monolog\Logger
{
}
14 changes: 14 additions & 0 deletions src/Logger/Handler/FactFinderErrorHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace Omikron\Factfinder\Logger\Handler;

use Magento\Framework\Logger\Handler\Base as BaseHandler;
use Monolog\Logger as MonologLogger;

class FactFinderErrorHandler extends BaseHandler
{
protected $loggerType = MonologLogger::ERROR;
protected $fileName = '/var/log/factfinder.log';
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Omikron\FactFinder\Communication\Client\ClientBuilder;
use Omikron\FactFinder\Communication\Client\ClientInterface;
use Omikron\FactFinder\Communication\Credentials;
use Omikron\Factfinder\Logger\FactFinderLogger;
use Omikron\Factfinder\Model\Api\CredentialsFactory;
use Omikron\Factfinder\Model\Config\AuthConfig;
use PHPUnit\Framework\MockObject\MockObject;
Expand Down Expand Up @@ -63,7 +64,8 @@ protected function setUp(): void
$this->createConfiguredMock(JsonFactory::class, ['create' => $this->createMock(JsonResult::class)]),
$credentialsFactory,
$this->createMock(AuthConfig::class),
$this->builderMock
$this->builderMock,
$this->createMock(FactFinderLogger::class)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Controller\Result\Json as JsonResult;
use Magento\Framework\Controller\Result\JsonFactory;
use Omikron\Factfinder\Logger\FactFinderLogger;
use Omikron\Factfinder\Model\Config\FtpConfig;
use Omikron\Factfinder\Model\FtpUploader;
use PHPUnit\Framework\MockObject\MockObject;
Expand Down Expand Up @@ -77,7 +78,8 @@ protected function setUp(): void
$this->createConfiguredMock(Context::class, ['getRequest' => $this->request]),
$this->createConfiguredMock(JsonFactory::class, ['create' => $this->jsonResult]),
$this->ftpUploader,
$this->createMock(FtpConfig::class)
$this->createMock(FtpConfig::class),
$this->createMock(FactFinderLogger::class)
);
}
}
13 changes: 13 additions & 0 deletions src/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,17 @@
</argument>
</arguments>
</type>
<type name="Omikron\Factfinder\Logger\Handler\FactFinderErrorHandler">
<arguments>
<argument name="filesystem" xsi:type="object">Magento\Framework\Filesystem\Driver\File</argument>
</arguments>
</type>
<type name="Omikron\Factfinder\Logger\FactFinderLogger">
<arguments>
<argument name="name" xsi:type="string">FACT-Finder</argument>
<argument name="handlers" xsi:type="array">
<item name="system" xsi:type="object">Omikron\Factfinder\Logger\Handler\FactFinderErrorHandler</item>
</argument>
</arguments>
</type>
</config>