File tree Expand file tree Collapse file tree 12 files changed +47
-44
lines changed Expand file tree Collapse file tree 12 files changed +47
-44
lines changed Original file line number Diff line number Diff line change 99namespace Opengento \WebapiLogger \Model ;
1010
1111use Magento \Framework \Exception \LocalizedException ;
12- use Opengento \WebapiLogger \Model \ResourceModel \LogResourceModel ;
12+ use Opengento \WebapiLogger \Model \ResourceModel \Log as LogResource ;
1313
1414class Clean
1515{
1616 public function __construct (
1717 private Config $ config ,
18- private LogResourceModel $ logResourceModel
18+ private LogResource $ logResourceModel
1919 ) {}
2020
21+ /**
22+ * @throws LocalizedException
23+ */
2124 public function cleanAll (): void
2225 {
2326 $ this ->logResourceModel ->getConnection ()->truncateTable ($ this ->logResourceModel ->getMainTable ());
@@ -32,7 +35,7 @@ public function clean(): void
3235 $ this ->logResourceModel ->getMainTable (),
3336 sprintf (
3437 '%s < NOW() - INTERVAL %s HOUR ' ,
35- LogResourceModel ::CREATED_AT ,
38+ LogResource ::CREATED_AT ,
3639 $ this ->config ->getCleanOlderThanHours ()
3740 )
3841 );
Original file line number Diff line number Diff line change 1313use Opengento \WebapiLogger \Model \Config \SaveMode ;
1414
1515use function array_map ;
16+ use function explode ;
1617
1718class Config
1819{
@@ -33,7 +34,7 @@ public function getSaveModes(): array
3334 {
3435 return array_map (
3536 static fn (string $ saveMode ): SaveMode => SaveMode::from ($ saveMode ),
36- $ this ->scopeConfig ->getValue (self ::WEBAPI_LOGS_SAVE_MODES )
37+ explode ( ' , ' , ( string ) $ this ->scopeConfig ->getValue (self ::WEBAPI_LOGS_SAVE_MODES ) )
3738 );
3839 }
3940
Original file line number Diff line number Diff line change 99namespace Opengento \WebapiLogger \Model \Config \Source ;
1010
1111use Magento \Framework \Data \OptionSourceInterface ;
12- use Opengento \WebapiLogger \Model \ResourceModel \Entity \ LogCollection ;
13- use Opengento \WebapiLogger \Model \ResourceModel \Entity \ LogCollectionFactory ;
12+ use Opengento \WebapiLogger \Model \ResourceModel \Log \ CollectionFactory ;
13+ use Opengento \WebapiLogger \Model \ResourceModel \Log \ Collection ;
1414
1515class Code implements OptionSourceInterface
1616{
17- public function __construct (private LogCollectionFactory $ logCollectionFactory ) {}
17+ public function __construct (private CollectionFactory $ collectionFactory ) {}
1818
1919 public function toOptionArray (): array
2020 {
21- /** @var LogCollection $logsCollection */
22- $ logsCollection = $ this ->logCollectionFactory ->create ();
23- $ logsCollection ->addFieldToSelect ('response_code ' );
24- $ logsCollection ->distinct (true );
21+ /** @var Collection $collection */
22+ $ collection = $ this ->collectionFactory ->create ();
23+ $ collection ->addFieldToSelect ('response_code ' );
24+ $ collection ->distinct (true );
2525
26- return $ logsCollection ->responseCodeToOptionArray ();
26+ return $ collection ->responseCodeToOptionArray ();
2727 }
2828}
Original file line number Diff line number Diff line change 99namespace Opengento \WebapiLogger \Model \Config \Source ;
1010
1111use Magento \Framework \Data \OptionSourceInterface ;
12- use Opengento \WebapiLogger \Model \ResourceModel \Entity \ LogCollection ;
13- use Opengento \WebapiLogger \Model \ResourceModel \Entity \ LogCollectionFactory ;
12+ use Opengento \WebapiLogger \Model \ResourceModel \Log \ CollectionFactory ;
13+ use Opengento \WebapiLogger \Model \ResourceModel \Log \ Collection ;
1414
1515class Methods implements OptionSourceInterface
1616{
17- public function __construct (private LogCollectionFactory $ logCollectionFactory ) {}
17+ public function __construct (private CollectionFactory $ collectionFactory ) {}
1818
1919 public function toOptionArray (): array
2020 {
21- /** @var LogCollection $logsCollection */
22- $ logsCollection = $ this ->logCollectionFactory ->create ();
23- $ logsCollection ->addFieldToSelect ('request_method ' );
24- $ logsCollection ->distinct (true );
21+ /** @var Collection $collection */
22+ $ collection = $ this ->collectionFactory ->create ();
23+ $ collection ->addFieldToSelect ('request_method ' );
24+ $ collection ->distinct (true );
2525
26- return $ logsCollection ->requestMethodToOptionArray ();
26+ return $ collection ->requestMethodToOptionArray ();
2727 }
2828}
Original file line number Diff line number Diff line change 99namespace Opengento \WebapiLogger \Model \Config \Source ;
1010
1111use Magento \Framework \Data \OptionSourceInterface ;
12- use Opengento \WebapiLogger \Model \ResourceModel \Entity \ LogCollection ;
13- use Opengento \WebapiLogger \Model \ResourceModel \Entity \ LogCollectionFactory ;
12+ use Opengento \WebapiLogger \Model \ResourceModel \Log \ CollectionFactory ;
13+ use Opengento \WebapiLogger \Model \ResourceModel \Log \ Collection ;
1414
1515class RequestorIp implements OptionSourceInterface
1616{
17- public function __construct (private LogCollectionFactory $ logCollectionFactory ) {}
17+ public function __construct (private CollectionFactory $ collectionFactory ) {}
1818
1919 public function toOptionArray (): array
2020 {
21- /** @var LogCollection $logsCollection */
22- $ logsCollection = $ this ->logCollectionFactory ->create ();
23- $ logsCollection ->addFieldToSelect ('requestor_ip ' );
24- $ logsCollection ->distinct (true );
21+ /** @var Collection $collection */
22+ $ collection = $ this ->collectionFactory ->create ();
23+ $ collection ->addFieldToSelect ('requestor_ip ' );
24+ $ collection ->distinct (true );
2525
26- return $ logsCollection ->requestorIpToOptionArray ();
26+ return $ collection ->requestorIpToOptionArray ();
2727 }
2828}
Original file line number Diff line number Diff line change 99namespace Opengento \WebapiLogger \Model ;
1010
1111use Magento \Framework \Model \AbstractModel ;
12- use Opengento \WebapiLogger \Model \ResourceModel \LogResourceModel ;
12+ use Opengento \WebapiLogger \Model \ResourceModel \Log as LogResource ;
1313
1414class Log extends AbstractModel
1515{
1616 protected function _construct (): void
1717 {
18- $ this ->_init (LogResourceModel ::class);
18+ $ this ->_init (LogResource ::class);
1919 }
2020}
Original file line number Diff line number Diff line change 1010
1111use Magento \Framework \Exception \AlreadyExistsException ;
1212use Opengento \WebapiLogger \Model \Config \SaveMode ;
13- use Opengento \WebapiLogger \Model \ResourceModel \LogResourceModel ;
13+ use Opengento \WebapiLogger \Model \ResourceModel \Log as LogResource ;
1414use Psr \Log \LoggerInterface ;
1515
1616use function in_array ;
1717
1818class LoggerManager
1919{
2020 public function __construct (
21- private LogResourceModel $ logResourceModel ,
21+ private LogResource $ logResourceModel ,
2222 private Config $ config ,
2323 private LoggerInterface $ logger
2424 ) {}
Original file line number Diff line number Diff line change 1010
1111use Magento \Framework \Model \ResourceModel \Db \AbstractDb ;
1212
13- class LogResourceModel extends AbstractDb
13+ class Log extends AbstractDb
1414{
1515 public const CREATED_AT = 'created_at ' ;
1616
Original file line number Diff line number Diff line change 66
77declare (strict_types=1 );
88
9- namespace Opengento \WebapiLogger \Model \ResourceModel \Entity ;
9+ namespace Opengento \WebapiLogger \Model \ResourceModel \Log ;
1010
1111use Magento \Framework \Model \ResourceModel \Db \Collection \AbstractCollection ;
1212use Opengento \WebapiLogger \Model \Log ;
13- use Opengento \WebapiLogger \Model \ResourceModel \LogResourceModel ;
13+ use Opengento \WebapiLogger \Model \ResourceModel \Log as LogResource ;
1414
15- class LogCollection extends AbstractCollection
15+ class Collection extends AbstractCollection
1616{
1717 protected $ _idFieldName = 'log_id ' ;
1818 protected $ _eventPrefix = 'webapi_log_collection ' ;
1919 protected $ _eventObject = 'logs_collection ' ;
2020
2121 protected function _construct (): void
2222 {
23- $ this ->_init (Log::class, LogResourceModel ::class);
23+ $ this ->_init (Log::class, LogResource ::class);
2424 }
2525
2626 public function responseCodeToOptionArray (): array
Original file line number Diff line number Diff line change @@ -49,10 +49,6 @@ bin/magento setup:upgrade
4949
5050## Features
5151
52- ### Country to store mapping
53-
54- Define many countries to many stores relation. This configuration will allows Magento to map stores with countries.
55-
5652## Settings
5753
5854The configuration for this module is available in ` Stores > Configuration > System > Webapi Logs ` .
@@ -73,6 +69,9 @@ If you disable the Secret Mode this module will logs everything passes in the we
7369
7470<img src =" https://github.com/opengento/magento2-webapi-logger/blob/main/screenshots/screen4.png " />
7571
72+ It is now possible to log the webapi request and response to filesystem or any handler that follow the PSR Log.
73+ You can register your handlers to ` Opengento\WebapiLogger\Logger ` . The module use the ` debug ` level to log the request and response.
74+
7675## Support
7776
7877Raise a new [ request] ( https://github.com/opengento/magento2-webapi-logger/issues ) to the issue tracker.
You can’t perform that action at this time.
0 commit comments