feat: actualiza el sistema de logging para usar un canal específico para REPUVE Nacional
This commit is contained in:
parent
1566c891a5
commit
c0d0e8dd86
@ -6,6 +6,7 @@
|
|||||||
use App\Models\Error;
|
use App\Models\Error;
|
||||||
use App\Models\Setting;
|
use App\Models\Setting;
|
||||||
use App\Helpers\EncryptionHelper;
|
use App\Helpers\EncryptionHelper;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class RepuveService
|
class RepuveService
|
||||||
{
|
{
|
||||||
@ -58,9 +59,9 @@ private function loadCredentials(): void
|
|||||||
$this->username = $credentials['username'];
|
$this->username = $credentials['username'];
|
||||||
$this->password = $credentials['password'];
|
$this->password = $credentials['password'];
|
||||||
|
|
||||||
logger()->info('RepuveService: Credenciales cargadas correctamente desde BD');
|
Log::channel('repuve_nacional')->info('RepuveService: Credenciales cargadas correctamente desde BD');
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
logger()->error('RepuveService: Error al cargar credenciales', [
|
Log::channel('repuve_nacional')->error('RepuveService: Error al cargar credenciales', [
|
||||||
'error' => $e->getMessage()
|
'error' => $e->getMessage()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -76,7 +77,7 @@ private function loadCredentials(): void
|
|||||||
*/
|
*/
|
||||||
private function ejecutarSolicitudSoap(\CurlHandle $ch, string $operacion, string $url, string $soapBody, array $contexto = []): array
|
private function ejecutarSolicitudSoap(\CurlHandle $ch, string $operacion, string $url, string $soapBody, array $contexto = []): array
|
||||||
{
|
{
|
||||||
logger()->info("REPUVE Nacional [{$operacion}]: Enviando solicitud al servidor", array_merge([
|
Log::channel('repuve_nacional')->info("REPUVE Nacional [{$operacion}]: Enviando solicitud al servidor", array_merge([
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'soap_body' => $soapBody,
|
'soap_body' => $soapBody,
|
||||||
], $contexto));
|
], $contexto));
|
||||||
@ -89,16 +90,16 @@ private function ejecutarSolicitudSoap(\CurlHandle $ch, string $operacion, strin
|
|||||||
$curlError = curl_error($ch);
|
$curlError = curl_error($ch);
|
||||||
|
|
||||||
if ($curlError) {
|
if ($curlError) {
|
||||||
logger()->error("REPUVE Nacional [{$operacion}]: Sin conexión con el servidor", array_merge([
|
Log::channel('repuve_nacional')->error("REPUVE Nacional [{$operacion}]: Sin conexión con el servidor", array_merge([
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'curl_error' => $curlError,
|
'curl_error' => $curlError,
|
||||||
'elapsed_ms' => $elapsedMs,
|
'lapso_ms' => $elapsedMs,
|
||||||
], $contexto));
|
], $contexto));
|
||||||
} else {
|
} else {
|
||||||
logger()->info("REPUVE Nacional [{$operacion}]: Respuesta recibida", array_merge([
|
Log::channel('repuve_nacional')->info("REPUVE Nacional [{$operacion}]: Respuesta recibida", array_merge([
|
||||||
'url' => $url,
|
'url' => $url,
|
||||||
'http_code' => $httpCode,
|
'http_code' => $httpCode,
|
||||||
'elapsed_ms' => $elapsedMs,
|
'lapso_ms' => $elapsedMs,
|
||||||
'response_length' => strlen($response ?: ''),
|
'response_length' => strlen($response ?: ''),
|
||||||
'response' => $response,
|
'response' => $response,
|
||||||
], $contexto));
|
], $contexto));
|
||||||
@ -108,7 +109,7 @@ private function ejecutarSolicitudSoap(\CurlHandle $ch, string $operacion, strin
|
|||||||
'response' => $response,
|
'response' => $response,
|
||||||
'http_code' => $httpCode,
|
'http_code' => $httpCode,
|
||||||
'curl_error' => $curlError,
|
'curl_error' => $curlError,
|
||||||
'elapsed_ms' => $elapsedMs,
|
'lapso_ms' => $elapsedMs,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -267,9 +268,9 @@ public function verificarRobo(?string $niv = null, ?string $placa = null): array
|
|||||||
$this->asegurarCargaCredenciales();
|
$this->asegurarCargaCredenciales();
|
||||||
|
|
||||||
if (empty($niv) && empty($placa)) {
|
if (empty($niv) && empty($placa)) {
|
||||||
logger()->warning('REPUVE verificarRobo: No se proporcionó NIV ni PLACA');
|
Log::channel('repuve_nacional')->warning('REPUVE verificarRobo: No se proporcionó NIV ni PLACA');
|
||||||
return [
|
return [
|
||||||
'is_robado' => false,
|
'es_robado' => false,
|
||||||
'has_error' => true,
|
'has_error' => true,
|
||||||
'error_message' => 'Debe proporcionar al menos NIV o PLACA para verificar robo',
|
'error_message' => 'Debe proporcionar al menos NIV o PLACA para verificar robo',
|
||||||
];
|
];
|
||||||
@ -286,12 +287,12 @@ public function verificarRobo(?string $niv = null, ?string $placa = null): array
|
|||||||
$arg2 = '||' . $placa . str_repeat('|', 5);
|
$arg2 = '||' . $placa . str_repeat('|', 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger()->info('REPUVE verificarRobo: Cadena construida', [
|
Log::channel('repuve_nacional')->info('REPUVE verificarRobo: Cadena construida', [
|
||||||
'niv' => $niv,
|
'niv' => $niv,
|
||||||
'placa' => $placa,
|
'placa' => $placa,
|
||||||
'arg2' => $arg2,
|
'arg2' => $arg2,
|
||||||
'total_pipes' => substr_count($arg2, '|'),
|
'total_pipes' => substr_count($arg2, '|'),
|
||||||
'ejemplo_visual' => str_replace('|', ' | ', $arg2),
|
'ejemplo' => str_replace('|', ' | ', $arg2),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
@ -350,7 +351,7 @@ public function verificarRobo(?string $niv = null, ?string $placa = null): array
|
|||||||
|
|
||||||
// Si hubo error al parsear, loguear pero retornar el resultado completo
|
// Si hubo error al parsear, loguear pero retornar el resultado completo
|
||||||
if ($resultado['has_error'] ?? false) {
|
if ($resultado['has_error'] ?? false) {
|
||||||
logger()->warning('REPUVE verificarRobo: Error al parsear respuesta', [
|
Log::channel('repuve_nacional')->warning('REPUVE verificarRobo: Error al parsear respuesta', [
|
||||||
'niv' => $niv,
|
'niv' => $niv,
|
||||||
'placa' => $placa,
|
'placa' => $placa,
|
||||||
'error' => $resultado['error_message'] ?? 'Desconocido',
|
'error' => $resultado['error_message'] ?? 'Desconocido',
|
||||||
@ -363,13 +364,13 @@ public function verificarRobo(?string $niv = null, ?string $placa = null): array
|
|||||||
unset($ch);
|
unset($ch);
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
logger()->error('REPUVE verificarRobo: Excepción capturada', [
|
Log::channel('repuve_nacional')->error('REPUVE verificarRobo: Excepción capturada', [
|
||||||
'niv' => $niv,
|
'niv' => $niv,
|
||||||
'placa' => $placa,
|
'placa' => $placa,
|
||||||
'exception' => $e->getMessage(),
|
'exception' => $e->getMessage(),
|
||||||
]);
|
]);
|
||||||
return [
|
return [
|
||||||
'is_robado' => false,
|
'es_robado' => false,
|
||||||
'has_error' => true,
|
'has_error' => true,
|
||||||
'error_message' => 'Excepción capturada: ' . $e->getMessage(),
|
'error_message' => 'Excepción capturada: ' . $e->getMessage(),
|
||||||
];
|
];
|
||||||
@ -441,7 +442,7 @@ public function consultarVehiculo(?string $niv = null, ?string $placa = null)
|
|||||||
$resultado = $this->parseConsultarVehiculoResponse($response);
|
$resultado = $this->parseConsultarVehiculoResponse($response);
|
||||||
|
|
||||||
if ($resultado['has_error'] ?? false) {
|
if ($resultado['has_error'] ?? false) {
|
||||||
logger()->warning('REPUVE consultarVehiculo: Error al parsear', [
|
Log::channel('repuve_nacional')->warning('REPUVE consultarVehiculo: Error al parsear', [
|
||||||
'niv' => $niv,
|
'niv' => $niv,
|
||||||
'placa' => $placa,
|
'placa' => $placa,
|
||||||
'error' => $resultado['error_message'] ?? 'Desconocido',
|
'error' => $resultado['error_message'] ?? 'Desconocido',
|
||||||
@ -453,7 +454,7 @@ public function consultarVehiculo(?string $niv = null, ?string $placa = null)
|
|||||||
unset($ch);
|
unset($ch);
|
||||||
}
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
logger()->error('REPUVE consultarVehiculo: Excepción', [
|
Log::channel('repuve_nacional')->error('REPUVE consultarVehiculo: Excepción', [
|
||||||
'niv' => $niv,
|
'niv' => $niv,
|
||||||
'placa' => $placa,
|
'placa' => $placa,
|
||||||
'exception' => $e->getMessage(),
|
'exception' => $e->getMessage(),
|
||||||
@ -674,7 +675,7 @@ private function parseRoboResponse(string $soapResponse, string $valor): array
|
|||||||
preg_match('/<return>(.*?)<\/return>/s', $soapResponse, $matches);
|
preg_match('/<return>(.*?)<\/return>/s', $soapResponse, $matches);
|
||||||
|
|
||||||
if (!isset($matches[1])) {
|
if (!isset($matches[1])) {
|
||||||
logger()->error('REPUVE parseRoboResponse: No se encontró tag <return>', [
|
Log::channel('repuve_nacional')->error('REPUVE parseRoboResponse: No se encontró tag <return>', [
|
||||||
'soap_response' => substr($soapResponse, 0, 500),
|
'soap_response' => substr($soapResponse, 0, 500),
|
||||||
'valor' => $valor,
|
'valor' => $valor,
|
||||||
]);
|
]);
|
||||||
@ -692,7 +693,7 @@ private function parseRoboResponse(string $soapResponse, string $valor): array
|
|||||||
if (preg_match('/(ERR|ERROR|err|error):(-?\d+)/i', $contenido, $errorMatch)) {
|
if (preg_match('/(ERR|ERROR|err|error):(-?\d+)/i', $contenido, $errorMatch)) {
|
||||||
$errorCode = $errorMatch[2];
|
$errorCode = $errorMatch[2];
|
||||||
|
|
||||||
logger()->warning('REPUVE parseRoboResponse: Servicio retornó error', [
|
Log::channel('repuve_nacional')->warning('REPUVE parseRoboResponse: Servicio retornó error', [
|
||||||
'error_code' => $errorCode,
|
'error_code' => $errorCode,
|
||||||
'contenido' => $contenido,
|
'contenido' => $contenido,
|
||||||
'valor' => $valor,
|
'valor' => $valor,
|
||||||
@ -700,7 +701,7 @@ private function parseRoboResponse(string $soapResponse, string $valor): array
|
|||||||
|
|
||||||
return [
|
return [
|
||||||
'has_error' => true,
|
'has_error' => true,
|
||||||
'is_robado' => false,
|
'es_robado' => false,
|
||||||
'error_code' => $errorCode,
|
'error_code' => $errorCode,
|
||||||
'error_message' => "Error REPUVE código {$errorCode}",
|
'error_message' => "Error REPUVE código {$errorCode}",
|
||||||
'raw_response' => $contenido,
|
'raw_response' => $contenido,
|
||||||
@ -718,7 +719,7 @@ private function parseRoboResponse(string $soapResponse, string $valor): array
|
|||||||
|
|
||||||
$roboData = [
|
$roboData = [
|
||||||
'has_error' => false,
|
'has_error' => false,
|
||||||
'is_robado' => $isRobado,
|
'es_robado' => $isRobado,
|
||||||
'indicador' => $indicador,
|
'indicador' => $indicador,
|
||||||
'fecha_robo' => $valores[1] ?? null,
|
'fecha_robo' => $valores[1] ?? null,
|
||||||
'placa' => $valores[2] ?? null,
|
'placa' => $valores[2] ?? null,
|
||||||
@ -732,7 +733,7 @@ private function parseRoboResponse(string $soapResponse, string $valor): array
|
|||||||
|
|
||||||
// Log importante si está robado
|
// Log importante si está robado
|
||||||
if ($isRobado) {
|
if ($isRobado) {
|
||||||
logger()->warning('REPUVE: Vehículo reportado como ROBADO', [
|
Log::channel('repuve_nacional')->warning('REPUVE: Vehículo reportado como ROBADO', [
|
||||||
'valor_buscado' => $valor,
|
'valor_buscado' => $valor,
|
||||||
'niv' => $roboData['niv'],
|
'niv' => $roboData['niv'],
|
||||||
'placa' => $roboData['placa'],
|
'placa' => $roboData['placa'],
|
||||||
@ -741,7 +742,7 @@ private function parseRoboResponse(string $soapResponse, string $valor): array
|
|||||||
'denunciante' => $roboData['denunciante'],
|
'denunciante' => $roboData['denunciante'],
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
logger()->info('REPUVE: Vehículo NO reportado como robado', [
|
Log::channel('repuve_nacional')->info('REPUVE: Vehículo NO reportado como robado', [
|
||||||
'valor_buscado' => $valor,
|
'valor_buscado' => $valor,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@ -750,7 +751,7 @@ private function parseRoboResponse(string $soapResponse, string $valor): array
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Si no tiene formato reconocido
|
// Si no tiene formato reconocido
|
||||||
logger()->error('REPUVE parseRoboResponse: Formato desconocido', [
|
Log::channel('repuve_nacional')->error('REPUVE parseRoboResponse: Formato desconocido', [
|
||||||
'contenido' => $contenido,
|
'contenido' => $contenido,
|
||||||
'valor' => $valor,
|
'valor' => $valor,
|
||||||
]);
|
]);
|
||||||
|
|||||||
@ -137,11 +137,12 @@
|
|||||||
],
|
],
|
||||||
|
|
||||||
'padron_estatal' => [
|
'padron_estatal' => [
|
||||||
'driver' => 'daily',
|
'driver' => 'single',
|
||||||
'path' => storage_path('logs/padron-estatal.log'),
|
'path' => storage_path('logs/padron-estatal.log'),
|
||||||
'level' => 'debug',
|
],
|
||||||
'days' => 14,
|
'repuve_nacional' => [
|
||||||
'replace_placeholders' => true,
|
'driver' => 'single',
|
||||||
|
'path' => storage_path('logs/repuve-nacional.log'),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user