Skip to content

Commit 54307b3

Browse files
committed
#102 Правка вывода логов
1 parent e5ddcff commit 54307b3

4 files changed

+20
-18
lines changed

Lib/Bitrix24Integration.php

+7-11
Original file line numberDiff line numberDiff line change
@@ -373,19 +373,19 @@ private function query(string $url, array $data, $needBuildQuery = true): array
373373
// Проверяем наличие ошибки:
374374
$error_name = $response['error'] ?? '';
375375
} elseif (in_array($error_name,['wrong_client','NO_AUTH_FOUND'], true)) {
376-
$this->mainLogger->writeError('Fail REST response ' . json_encode($response));
377-
$this->mainLogger->writeError("$error_name: session: ".json_encode($this->SESSION));
376+
$this->mainLogger->writeError($response, 'Fail REST response');
377+
$this->mainLogger->writeError($this->SESSION, "$error_name: session: ");
378378
} elseif ('QUERY_LIMIT_EXCEEDED' === $error_name) {
379379
$this->mainLogger->writeInfo('Too many requests. Sleeping 1s ... ');
380380
sleep(1);
381381
$response = $this->execCurl($url, $curlOptions, $status, $headersResponse, $totalTime);
382382
$error_name = $response['error'] ?? '';
383383
}elseif(!empty($response['result_error'])){
384-
$this->mainLogger->writeInfo("RESPONSE-ERROR: ".json_encode($response['result_error']));
384+
$this->mainLogger->writeInfo($response['result_error'], "RESPONSE-ERROR");
385385
}
386386

387387
if (!empty($error_name)) {
388-
$this->mainLogger->writeError('Fail REST response ' . json_encode($response));
388+
$this->mainLogger->writeError($response, 'Fail REST response');
389389
}
390390
}
391391
if(isset( $data['cmd'])){
@@ -408,7 +408,7 @@ private function query(string $url, array $data, $needBuildQuery = true): array
408408
unset($query['auth']);
409409
$queues[$index] = $query;
410410
}
411-
$this->mainLogger->writeInfo("REQUEST: ".json_encode($queues, JSON_UNESCAPED_UNICODE));
411+
$this->mainLogger->writeInfo($queues, 'REQUEST');
412412
$result = $response['result']["result"]??[];
413413
// Чистым массив перед выводом в лог.
414414
if(is_array($result)){
@@ -418,17 +418,13 @@ private function query(string $url, array $data, $needBuildQuery = true): array
418418
}
419419
}
420420
}
421-
$this->mainLogger->writeInfo("RESPONSE: ".json_encode($result, JSON_UNESCAPED_UNICODE));
421+
$this->mainLogger->writeInfo($result, 'RESPONSE');
422422
}
423423
}
424424
$this->checkErrorInResponse($response, $status);
425425
$delta = microtime(true) - $startTime;
426426
if ($delta > 5 || $totalTime > 5) {
427-
$this->mainLogger->writeError(
428-
"Slow response. PHP time:{$delta}s, cURL time: {$totalTime}, url:{$url}, Data:$q4Dump, Response: " . json_encode(
429-
$response
430-
)
431-
);
427+
$this->mainLogger->writeError($response, "Slow response. PHP time:{$delta}s, cURL time: {$totalTime}, url:{$url}, Data:$q4Dump, Response: ");
432428
}
433429

434430
$this->mainLogger->rotate();

Lib/Logger.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,23 @@ public function rotate(): void
9696
}
9797
}
9898

99-
public function writeError($data): void
99+
public function writeError($data, string $header = ''): void
100100
{
101101
if ($this->debug) {
102-
$this->logger->error($this->getDecodedString($data));
102+
if(!empty($header)){
103+
$header.= "$header: ";
104+
}
105+
$this->logger->error($header . $this->getDecodedString($data));
103106
}
104107
}
105108

106-
public function writeInfo($data): void
109+
public function writeInfo($data, string $header = ''): void
107110
{
108111
if ($this->debug) {
109-
$this->logger->info($this->getDecodedString($data));
112+
if(!empty($header)){
113+
$header.= ": ";
114+
}
115+
$this->logger->info($header . $this->getDecodedString($data));
110116
}
111117
}
112118

bin/WorkerBitrix24IntegrationAMI.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private function updateSettings():void{
205205
}
206206
$this->updateExternalLines();
207207
$this->b24->updateSettings();
208-
$this->logger->writeInfo(['usersSettingsB24'=> $this->b24->usersSettingsB24]);
208+
$this->logger->writeInfo($this->b24->usersSettingsB24, 'usersSettingsB24');
209209

210210
}
211211

@@ -272,7 +272,7 @@ public function callback($parameters):void{
272272
}
273273
$stringData = base64_decode($parameters['AgiData']);
274274
$data = json_decode($stringData, true);
275-
$this->logger->writeInfo($data['action'].': '.$stringData);
275+
$this->logger->writeInfo($stringData, $data['action']);
276276
switch ($data['action']) {
277277
case 'hangup_chan':
278278
$this->actionHangupChan($data);

bin/WorkerBitrix24IntegrationHTTP.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function invokeRest($client): void
143143
*/
144144
public function invokeRestCheckResponse($response,$tube, $partResponse): void
145145
{
146-
$this->b24->logger->writeInfo("start response $response, $tube");
146+
$this->b24->mainLogger->writeInfo([$response, $partResponse],"start response to tube $tube");
147147
$resFile = ConnectorDb::saveResultInTmpFile($partResponse);
148148
$this->queueAgent->publish($resFile, $tube);
149149
}

0 commit comments

Comments
 (0)