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 9
9
namespace Opengento \WebapiLogger \Model ;
10
10
11
11
use Magento \Framework \Exception \LocalizedException ;
12
- use Opengento \WebapiLogger \Model \ResourceModel \LogResourceModel ;
12
+ use Opengento \WebapiLogger \Model \ResourceModel \Log as LogResource ;
13
13
14
14
class Clean
15
15
{
16
16
public function __construct (
17
17
private Config $ config ,
18
- private LogResourceModel $ logResourceModel
18
+ private LogResource $ logResourceModel
19
19
) {}
20
20
21
+ /**
22
+ * @throws LocalizedException
23
+ */
21
24
public function cleanAll (): void
22
25
{
23
26
$ this ->logResourceModel ->getConnection ()->truncateTable ($ this ->logResourceModel ->getMainTable ());
@@ -32,7 +35,7 @@ public function clean(): void
32
35
$ this ->logResourceModel ->getMainTable (),
33
36
sprintf (
34
37
'%s < NOW() - INTERVAL %s HOUR ' ,
35
- LogResourceModel ::CREATED_AT ,
38
+ LogResource ::CREATED_AT ,
36
39
$ this ->config ->getCleanOlderThanHours ()
37
40
)
38
41
);
Original file line number Diff line number Diff line change 13
13
use Opengento \WebapiLogger \Model \Config \SaveMode ;
14
14
15
15
use function array_map ;
16
+ use function explode ;
16
17
17
18
class Config
18
19
{
@@ -33,7 +34,7 @@ public function getSaveModes(): array
33
34
{
34
35
return array_map (
35
36
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 ) )
37
38
);
38
39
}
39
40
Original file line number Diff line number Diff line change 9
9
namespace Opengento \WebapiLogger \Model \Config \Source ;
10
10
11
11
use 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 ;
14
14
15
15
class Code implements OptionSourceInterface
16
16
{
17
- public function __construct (private LogCollectionFactory $ logCollectionFactory ) {}
17
+ public function __construct (private CollectionFactory $ collectionFactory ) {}
18
18
19
19
public function toOptionArray (): array
20
20
{
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 );
25
25
26
- return $ logsCollection ->responseCodeToOptionArray ();
26
+ return $ collection ->responseCodeToOptionArray ();
27
27
}
28
28
}
Original file line number Diff line number Diff line change 9
9
namespace Opengento \WebapiLogger \Model \Config \Source ;
10
10
11
11
use 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 ;
14
14
15
15
class Methods implements OptionSourceInterface
16
16
{
17
- public function __construct (private LogCollectionFactory $ logCollectionFactory ) {}
17
+ public function __construct (private CollectionFactory $ collectionFactory ) {}
18
18
19
19
public function toOptionArray (): array
20
20
{
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 );
25
25
26
- return $ logsCollection ->requestMethodToOptionArray ();
26
+ return $ collection ->requestMethodToOptionArray ();
27
27
}
28
28
}
Original file line number Diff line number Diff line change 9
9
namespace Opengento \WebapiLogger \Model \Config \Source ;
10
10
11
11
use 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 ;
14
14
15
15
class RequestorIp implements OptionSourceInterface
16
16
{
17
- public function __construct (private LogCollectionFactory $ logCollectionFactory ) {}
17
+ public function __construct (private CollectionFactory $ collectionFactory ) {}
18
18
19
19
public function toOptionArray (): array
20
20
{
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 );
25
25
26
- return $ logsCollection ->requestorIpToOptionArray ();
26
+ return $ collection ->requestorIpToOptionArray ();
27
27
}
28
28
}
Original file line number Diff line number Diff line change 9
9
namespace Opengento \WebapiLogger \Model ;
10
10
11
11
use Magento \Framework \Model \AbstractModel ;
12
- use Opengento \WebapiLogger \Model \ResourceModel \LogResourceModel ;
12
+ use Opengento \WebapiLogger \Model \ResourceModel \Log as LogResource ;
13
13
14
14
class Log extends AbstractModel
15
15
{
16
16
protected function _construct (): void
17
17
{
18
- $ this ->_init (LogResourceModel ::class);
18
+ $ this ->_init (LogResource ::class);
19
19
}
20
20
}
Original file line number Diff line number Diff line change 10
10
11
11
use Magento \Framework \Exception \AlreadyExistsException ;
12
12
use Opengento \WebapiLogger \Model \Config \SaveMode ;
13
- use Opengento \WebapiLogger \Model \ResourceModel \LogResourceModel ;
13
+ use Opengento \WebapiLogger \Model \ResourceModel \Log as LogResource ;
14
14
use Psr \Log \LoggerInterface ;
15
15
16
16
use function in_array ;
17
17
18
18
class LoggerManager
19
19
{
20
20
public function __construct (
21
- private LogResourceModel $ logResourceModel ,
21
+ private LogResource $ logResourceModel ,
22
22
private Config $ config ,
23
23
private LoggerInterface $ logger
24
24
) {}
Original file line number Diff line number Diff line change 10
10
11
11
use Magento \Framework \Model \ResourceModel \Db \AbstractDb ;
12
12
13
- class LogResourceModel extends AbstractDb
13
+ class Log extends AbstractDb
14
14
{
15
15
public const CREATED_AT = 'created_at ' ;
16
16
Original file line number Diff line number Diff line change 6
6
7
7
declare (strict_types=1 );
8
8
9
- namespace Opengento \WebapiLogger \Model \ResourceModel \Entity ;
9
+ namespace Opengento \WebapiLogger \Model \ResourceModel \Log ;
10
10
11
11
use Magento \Framework \Model \ResourceModel \Db \Collection \AbstractCollection ;
12
12
use Opengento \WebapiLogger \Model \Log ;
13
- use Opengento \WebapiLogger \Model \ResourceModel \LogResourceModel ;
13
+ use Opengento \WebapiLogger \Model \ResourceModel \Log as LogResource ;
14
14
15
- class LogCollection extends AbstractCollection
15
+ class Collection extends AbstractCollection
16
16
{
17
17
protected $ _idFieldName = 'log_id ' ;
18
18
protected $ _eventPrefix = 'webapi_log_collection ' ;
19
19
protected $ _eventObject = 'logs_collection ' ;
20
20
21
21
protected function _construct (): void
22
22
{
23
- $ this ->_init (Log::class, LogResourceModel ::class);
23
+ $ this ->_init (Log::class, LogResource ::class);
24
24
}
25
25
26
26
public function responseCodeToOptionArray (): array
Original file line number Diff line number Diff line change @@ -49,10 +49,6 @@ bin/magento setup:upgrade
49
49
50
50
## Features
51
51
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
-
56
52
## Settings
57
53
58
54
The 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
73
69
74
70
<img src =" https://github.com/opengento/magento2-webapi-logger/blob/main/screenshots/screen4.png " />
75
71
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
+
76
75
## Support
77
76
78
77
Raise 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