Skip to content

Commit c907867

Browse files
committed
Fix and logging update
1 parent 92ddc82 commit c907867

File tree

3 files changed

+35
-22
lines changed

3 files changed

+35
-22
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,12 @@ Upgrades & updates
488488

489489
- Todo: repository class to manage dedicated model.
490490

491-
### v5.1.0 (last stable)
491+
### v5.1.1 (last stable)
492+
493+
- Fixed method ```findAll```.
494+
- Updated endpoint logging level to ```debug``` and added client logging with level ```info```
495+
496+
### v5.1.0
492497

493498
- Added method ```findAll```.
494499
- Fixed empty array result issue.

src/Client.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function findOneBy(string $modelName, $criteria = null, array $options =
217217
*/
218218
public function findAll(string $modelName, array $options = []): array
219219
{
220-
return (array) $this->call($modelName, self::FIND, null, $options);
220+
return $this->findBy($modelName, null, $options);
221221
}
222222

223223
/**
@@ -271,6 +271,18 @@ public function listFields(string $modelName, array $options = []): array
271271
*/
272272
public function call(string $name, string $method, array $parameters = [], array $options = [])
273273
{
274+
$loggerContext = [
275+
'request_id' => uniqid('xmlrpc-request-', true),
276+
'name' => $name,
277+
'method' => $method,
278+
'parameters' => $parameters,
279+
'options' => $options,
280+
];
281+
282+
if ($this->logger) {
283+
$this->logger->info('Calling method {method} from {model}', $loggerContext);
284+
}
285+
274286
try {
275287
$result = $this->objectEndpoint->call('execute_kw', [
276288
$this->database,
@@ -280,7 +292,7 @@ public function call(string $name, string $method, array $parameters = [], array
280292
$method,
281293
$parameters,
282294
$this->encoder->encode($options, 'struct'),
283-
]);
295+
], $loggerContext);
284296

285297
/*
286298
* Added in v5.0.7
@@ -300,17 +312,22 @@ public function call(string $name, string $method, array $parameters = [], array
300312
return null !== $value;
301313
});
302314
}
303-
304-
return $result;
305315
} catch (RemoteException $e) {
306316
// Odoo raises an exception if the remote method does not return values (NULL).
307317
// This part allows to return null when it happens by ignoring the exception.
308318
if (preg_match('#cannot marshal None unless allow_none is enabled#', $e->getMessage())) {
309-
return null;
319+
$result = null;
320+
} else {
321+
throw $e;
310322
}
323+
}
311324

312-
throw $e;
325+
if ($this->logger) {
326+
$loggerContext['result'] = is_scalar($result) ? $result : json_encode($result);
327+
$this->logger->info('Request result: {result}', $loggerContext);
313328
}
329+
330+
return $result;
314331
}
315332

316333
public function version(): array

src/XmlRpc/Endpoint.php

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,9 @@ public function __toString(): string
4444
*
4545
* @return mixed
4646
*/
47-
public function call(string $method, array $args = [])
47+
public function call(string $method, array $args = [], array $loggerContext = [])
4848
{
49-
$context = [
50-
'request_id' => uniqid('xmlrpc-request-', true),
51-
'endpoint' => $this->client->path,
52-
'method' => $method,
53-
'input_data' => $args,
54-
];
49+
$loggerContext['endpoint'] = $this->client->path;
5550

5651
foreach ($args as $key => $arg) {
5752
$args[$key] = $this->encoder->encode($arg);
@@ -60,7 +55,7 @@ public function call(string $method, array $args = [])
6055
$context['encoded_data'] = $args;
6156

6257
if ($this->logger) {
63-
$this->logger->info('XML-RPC request with method "{method}"', $context);
58+
$this->logger->debug('XML-RPC request with method "{method}"', $loggerContext);
6459
}
6560

6661
try {
@@ -79,18 +74,14 @@ public function call(string $method, array $args = [])
7974
throw RemoteException::createFromXmlResult($faultCode, $response->faultString() ?: 'Unknown error');
8075
}
8176

82-
$context = [
83-
'request_id' => $context['request_id'],
84-
];
85-
8677
if ($this->logger) {
87-
$this->logger->info('XML-RPC response received', $context);
78+
$this->logger->debug('XML-RPC response received', $loggerContext);
8879
}
8980

9081
$data = $this->encoder->decode($response->val);
9182

9283
if ($this->logger) {
93-
$this->logger->info('XML-RPC response decoded', array_merge($context, [
84+
$this->logger->debug('XML-RPC response decoded', array_merge($loggerContext, [
9485
'data_type' => gettype($data),
9586
]));
9687
}
@@ -102,7 +93,7 @@ public function call(string $method, array $args = [])
10293
];
10394

10495
if ($this->logger) {
105-
$this->logger->info('XML-RPC response error: {message} - Code {code}', array_merge($context, $error));
96+
$this->logger->debug('XML-RPC response error: {message} - Code {code}', array_merge($loggerContext, $error));
10697
}
10798

10899
throw RemoteException::createFromXmlResult($error['code'], $error['message']);

0 commit comments

Comments
 (0)