From 3d13dd2876da9b185aa32db735e313d2cadf5ee5 Mon Sep 17 00:00:00 2001 From: Guilherme Andrade Del Cantoni Date: Mon, 27 May 2019 11:58:54 -0300 Subject: [PATCH] Melhoria no mecanismo de registro de log debug do módulo --- DebugPen.php | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ rn/ProcessarPendenciasRN.php | 17 ++++++++++++----- rn/ReceberProcedimentoRN.php | 26 ++++++-------------------- rn/ReceberReciboTramiteRN.php | 11 ++++++----- 4 files changed, 75 insertions(+), 30 deletions(-) create mode 100644 DebugPen.php diff --git a/DebugPen.php b/DebugPen.php new file mode 100644 index 0000000..1271d0f --- /dev/null +++ b/DebugPen.php @@ -0,0 +1,51 @@ +strDebugTag = $parStrDebugTag; + } + + public static function getInstance() + { + if (self::$instance == null) { + self::$instance = new DebugPen(); + } + return self::$instance; + } + + public function setStrDebugTag($parStrDebugTag=null){ + $this->strDebugTag = $parStrDebugTag; + } + + public function gravar($str, $numIdentacao=0, $bolLogTempoProcessamento=true) { + + $strDataLog = date("d/m/Y H:i:s"); + $strTag = (!is_null($this->strDebugTag)) ? "[" . $this->strDebugTag . "]": ""; + + $strLog = sprintf("[%s] %s %s %s", $strDataLog, $strTag, str_repeat(" ", $numIdentacao * 4), $str); + + //Registro de tempo de processamento desde último log + if($bolLogTempoProcessamento){ + $numTempoFinal = microtime(true); + if(is_null($this->numTempoUltimoLog)){ + //Inicializa contador de tempo de processamento + $this->numTempoUltimoLog = $numTempoFinal; + } else { + $numTempoProcessamento = round($numTempoFinal - $this->numTempoUltimoLog, 2); + $strLog .= " [tempo: +{$numTempoProcessamento}s]"; + $this->numTempoUltimoLog = $numTempoFinal; + } + } + + parent::gravar($strLog); + } +} diff --git a/rn/ProcessarPendenciasRN.php b/rn/ProcessarPendenciasRN.php index 315fbb6..47e59ba 100644 --- a/rn/ProcessarPendenciasRN.php +++ b/rn/ProcessarPendenciasRN.php @@ -6,6 +6,7 @@ class ProcessarPendenciasRN extends InfraAgendamentoTarefa { private static $instance = null; private $objGearmanWorker = null; + private $objPenDebug = null; const TIMEOUT_PROCESSAMENTO_JOB = 5400; @@ -26,6 +27,15 @@ class ProcessarPendenciasRN extends InfraAgendamentoTarefa { $this->objGearmanWorker = new GearmanWorker(); $this->objGearmanWorker->addServer("127.0.0.1", 4730); + + //Configuração dos logs de debug de processamento + $this->objPenDebug = DebugPen::getInstance(); + $this->objPenDebug->setStrDebugTag("PROCESSAMENTO"); + $this->objPenDebug->setBolLigado(true); + $this->objPenDebug->setBolDebugInfra(false); + $this->objPenDebug->setBolEcho(true); + $this->objPenDebug->limpar(); + $this->configurarCallbacks(); } @@ -163,12 +173,9 @@ class ProcessarPendenciasRN extends InfraAgendamentoTarefa }, null, self::TIMEOUT_PROCESSAMENTO_JOB); } - private function gravarLogDebug($strMensagem, $numIdentacao=0, $bolEcho=false) + private function gravarLogDebug($parStrMensagem, $parNumIdentacao=0, $parBolLogTempoProcessamento=false) { - $strDataLog = date("d/m/Y H:i:s"); - $strLog = sprintf("[%s] [PROCESSAMENTO] %s %s", $strDataLog, str_repeat(" ", $numIdentacao * 4), $strMensagem); - InfraDebug::getInstance()->gravar($strLog); - if(!InfraDebug::getInstance()->isBolEcho() && $bolEcho) echo sprintf("\n[%s] [PROCESSAMENTO] %s", $strDataLog, $strMensagem); + $this->objPenDebug->gravar($parStrMensagem, $parNumIdentacao, $parBolLogTempoProcessamento); } static function processarTarefa($strNomeTarefa, $strWorkload) diff --git a/rn/ReceberProcedimentoRN.php b/rn/ReceberProcedimentoRN.php index 063942e..b146375 100644 --- a/rn/ReceberProcedimentoRN.php +++ b/rn/ReceberProcedimentoRN.php @@ -10,6 +10,7 @@ class ReceberProcedimentoRN extends InfraRN private $objProcedimentoAndamentoRN; private $documentosRetirados = array(); public $destinatarioReal = null; + private $objPenDebug = null; public function __construct() { @@ -19,7 +20,8 @@ class ReceberProcedimentoRN extends InfraRN $this->objProcedimentoAndamentoRN = new ProcedimentoAndamentoRN(); $this->objReceberComponenteDigitalRN = new ReceberComponenteDigitalRN(); - $this->numTempoUltimoLog = null; + //Configuração dos logs de debug de processamento + $this->objPenDebug = DebugPen::getInstance(); } protected function inicializarObjInfraIBanco() @@ -137,7 +139,7 @@ class ReceberProcedimentoRN extends InfraRN $numTempoInicialValidacao = microtime(true); $this->objReceberComponenteDigitalRN->validarIntegridadeDoComponenteDigital($arrAnexosComponentes[$key][$componentePendente], $componentePendente, $parNumIdentificacaoTramite, $numOrdemComponente); - $numTempoTotalValidacao = round(microtime(true) - $numTempoInicialValidacao, 2); + $numTempoTotalValidacao = microtime(true) - $numTempoInicialValidacao; $numVelocidade = round($numTamanhoArquivoKB / $numTempoTotalValidacao, 2); $this->gravarLogDebug("Tempo total de validação de integridade: {$numTempoTotalValidacao}s ({$numVelocidade} kb/s)", 7); } @@ -1936,24 +1938,8 @@ class ReceberProcedimentoRN extends InfraRN } } - private function gravarLogDebug($strMensagem, $numIdentacao=0, $bolLogTempoProcessamento=true) + private function gravarLogDebug($parStrMensagem, $parNumIdentacao=0, $parBolLogTempoProcessamento=true) { - $strDataLog = date("d/m/Y H:i:s"); - $strLog = sprintf("[%s] [PROCESSAMENTO] %s %s", $strDataLog, str_repeat(" ", $numIdentacao * 4), $strMensagem); - - //Registro de tempo de processamento desde último log - if($bolLogTempoProcessamento){ - $numTempoFinal = microtime(true); - if(is_null($this->numTempoUltimoLog)){ - //Inicializa contador de tempo de processamento - $this->numTempoUltimoLog = $numTempoFinal; - } else { - $numTempoProcessamento = round($numTempoFinal - $this->numTempoUltimoLog, 2); - $strLog .= " [tempo: +{$numTempoProcessamento}s]"; - $this->numTempoUltimoLog = $numTempoFinal; - } - } - - InfraDebug::getInstance()->gravar($strLog); + $this->objPenDebug->gravar($parStrMensagem, $parNumIdentacao, $parBolLogTempoProcessamento); } } diff --git a/rn/ReceberReciboTramiteRN.php b/rn/ReceberReciboTramiteRN.php index 928e0b0..3b95405 100644 --- a/rn/ReceberReciboTramiteRN.php +++ b/rn/ReceberReciboTramiteRN.php @@ -6,13 +6,14 @@ class ReceberReciboTramiteRN extends InfraRN private $objProcessoEletronicoRN; private $objInfraParametro; private $objProcedimentoAndamentoRN; + private $objPenDebug = null; public function __construct() { - parent::__construct(); - - $this->objProcessoEletronicoRN = new ProcessoEletronicoRN(); - $this->objProcedimentoAndamentoRN = new ProcedimentoAndamentoRN(); + parent::__construct(); + $this->objProcessoEletronicoRN = new ProcessoEletronicoRN(); + $this->objProcedimentoAndamentoRN = new ProcedimentoAndamentoRN(); + $this->objPenDebug = DebugPen::getInstance(); } protected function inicializarObjInfraIBanco() @@ -33,7 +34,7 @@ class ReceberReciboTramiteRN extends InfraRN //Registra falha em log de debug mas não gera rollback na transação. //O rollback da transação poderia deixar a situação do processo inconsistênte já que o Barramento registrou anteriormente que o //recibo já havia sido obtido. O erro no fechamento não provoca impacto no andamento do processo - InfraDebug::getInstance()->gravar("Processo $strProtocoloFormatado não está aberto na unidade."); + $this->objPenDebug->gravar("Processo $strProtocoloFormatado não está aberto na unidade."); } $arrObjAtributoAndamentoDTO = array(); -- libgit2 0.21.2