Skip to content

Commit 8bb967e

Browse files
author
Pavel
committed
master: Fix log
1 parent 174d516 commit 8bb967e

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

src/Exceptions/JsonRpcHandler.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class JsonRpcHandler
1212
{
13-
protected const EXCEPTION_MESSAGE = 'JsonRpc (%s): #%d %s';
13+
protected const EXCEPTION_MESSAGE = 'JsonRpc (method:"%s", id:"%s", service:"%s"): #%d %s';
1414

1515
public function handle(\Exception $e)
1616
{
@@ -35,8 +35,15 @@ public function handle(\Exception $e)
3535
/** @var JsonRpcRequest $request */
3636
$request = app(JsonRpcRequest::class);
3737

38-
Log::channel(config('jsonrpc.logChannel', 'default'))
39-
->info(sprintf(self::EXCEPTION_MESSAGE, $request->id, $error->code, $error->message));
38+
$logContext = [
39+
'method' => $request->call->method,
40+
'call' => class_basename($request->controller) . '::' . $request->method,
41+
'id' => $request->id,
42+
'service' => $request->service,
43+
];
44+
45+
Log::channel(config('jsonrpc.log.channel', 'default'))
46+
->info('Error #' . $error->code . ': ' . $error->message, $logContext);
4047

4148
$handler = app(ExceptionHandler::class);
4249
$handler->report($e);

src/JsonRpcRequest.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
class JsonRpcRequest
1111
{
12-
protected const REQUEST_MESSAGE = 'JsonRpc (%s): New request (%s/%s)';
13-
protected const RESPONSE_MESSAGE = 'JsonRpc (%s): Successful request (%s/%s)';
14-
1512
public $call;
1613

1714
public $id;
@@ -48,14 +45,20 @@ public function handle()
4845
throw new JsonRpcException(JsonRpcException::CODE_INTERNAL_ERROR);
4946
}
5047

51-
Log::channel(config('jsonrpc.logChannel', 'default'))
52-
->info(sprintf(self::REQUEST_MESSAGE, $this->id, class_basename($this->controller), $this->method),
53-
ArrayHelper::fromObject($this->call));
48+
$logContext = [
49+
'method' => $this->call->method,
50+
'call' => class_basename($this->controller) . '::' . $this->method,
51+
'id' => $this->id,
52+
'service' => $this->service,
53+
];
54+
55+
Log::channel(config('jsonrpc.log.channel', 'default'))
56+
->info('New request', $logContext + ['request' => ArrayHelper::fromObject($this->call)]);
5457

5558
$result = $this->controller->{$this->method}(...$this->params);
5659

57-
Log::channel(config('jsonrpc.logChannel', 'default'))
58-
->info(sprintf(self::RESPONSE_MESSAGE, $this->id, class_basename($this->controller), $this->method));
60+
Log::channel(config('jsonrpc.log.channel', 'default'))
61+
->info('Successful request', $logContext);
5962

6063
return $result;
6164
}

0 commit comments

Comments
 (0)