Commit 3d13dd2876da9b185aa32db735e313d2cadf5ee5
1 parent
572912a3
Exists in
desenv
Melhoria no mecanismo de registro de log debug do módulo
Showing
4 changed files
with
75 additions
and
30 deletions
Show diff stats
... | ... | @@ -0,0 +1,51 @@ |
1 | +<? | |
2 | + | |
3 | +require_once dirname(__FILE__) . '/../../SEI.php'; | |
4 | + | |
5 | +class DebugPen extends InfraDebug { | |
6 | + | |
7 | + //Rótulo aplicado na mensagem de log para agrupar a sequência mensagens | |
8 | + private $strDebugTag = null; | |
9 | + private $numTempoUltimoLog = null; | |
10 | + private static $instance = null; | |
11 | + | |
12 | + public function __construct($parStrDebugTag=null){ | |
13 | + parent::__construct(); | |
14 | + $this->strDebugTag = $parStrDebugTag; | |
15 | + } | |
16 | + | |
17 | + public static function getInstance() | |
18 | + { | |
19 | + if (self::$instance == null) { | |
20 | + self::$instance = new DebugPen(); | |
21 | + } | |
22 | + return self::$instance; | |
23 | + } | |
24 | + | |
25 | + public function setStrDebugTag($parStrDebugTag=null){ | |
26 | + $this->strDebugTag = $parStrDebugTag; | |
27 | + } | |
28 | + | |
29 | + public function gravar($str, $numIdentacao=0, $bolLogTempoProcessamento=true) { | |
30 | + | |
31 | + $strDataLog = date("d/m/Y H:i:s"); | |
32 | + $strTag = (!is_null($this->strDebugTag)) ? "[" . $this->strDebugTag . "]": ""; | |
33 | + | |
34 | + $strLog = sprintf("[%s] %s %s %s", $strDataLog, $strTag, str_repeat(" ", $numIdentacao * 4), $str); | |
35 | + | |
36 | + //Registro de tempo de processamento desde último log | |
37 | + if($bolLogTempoProcessamento){ | |
38 | + $numTempoFinal = microtime(true); | |
39 | + if(is_null($this->numTempoUltimoLog)){ | |
40 | + //Inicializa contador de tempo de processamento | |
41 | + $this->numTempoUltimoLog = $numTempoFinal; | |
42 | + } else { | |
43 | + $numTempoProcessamento = round($numTempoFinal - $this->numTempoUltimoLog, 2); | |
44 | + $strLog .= " [tempo: +{$numTempoProcessamento}s]"; | |
45 | + $this->numTempoUltimoLog = $numTempoFinal; | |
46 | + } | |
47 | + } | |
48 | + | |
49 | + parent::gravar($strLog); | |
50 | + } | |
51 | +} | ... | ... |
rn/ProcessarPendenciasRN.php
... | ... | @@ -6,6 +6,7 @@ class ProcessarPendenciasRN extends InfraAgendamentoTarefa |
6 | 6 | { |
7 | 7 | private static $instance = null; |
8 | 8 | private $objGearmanWorker = null; |
9 | + private $objPenDebug = null; | |
9 | 10 | |
10 | 11 | const TIMEOUT_PROCESSAMENTO_JOB = 5400; |
11 | 12 | |
... | ... | @@ -26,6 +27,15 @@ class ProcessarPendenciasRN extends InfraAgendamentoTarefa |
26 | 27 | { |
27 | 28 | $this->objGearmanWorker = new GearmanWorker(); |
28 | 29 | $this->objGearmanWorker->addServer("127.0.0.1", 4730); |
30 | + | |
31 | + //Configuração dos logs de debug de processamento | |
32 | + $this->objPenDebug = DebugPen::getInstance(); | |
33 | + $this->objPenDebug->setStrDebugTag("PROCESSAMENTO"); | |
34 | + $this->objPenDebug->setBolLigado(true); | |
35 | + $this->objPenDebug->setBolDebugInfra(false); | |
36 | + $this->objPenDebug->setBolEcho(true); | |
37 | + $this->objPenDebug->limpar(); | |
38 | + | |
29 | 39 | $this->configurarCallbacks(); |
30 | 40 | } |
31 | 41 | |
... | ... | @@ -163,12 +173,9 @@ class ProcessarPendenciasRN extends InfraAgendamentoTarefa |
163 | 173 | }, null, self::TIMEOUT_PROCESSAMENTO_JOB); |
164 | 174 | } |
165 | 175 | |
166 | - private function gravarLogDebug($strMensagem, $numIdentacao=0, $bolEcho=false) | |
176 | + private function gravarLogDebug($parStrMensagem, $parNumIdentacao=0, $parBolLogTempoProcessamento=false) | |
167 | 177 | { |
168 | - $strDataLog = date("d/m/Y H:i:s"); | |
169 | - $strLog = sprintf("[%s] [PROCESSAMENTO] %s %s", $strDataLog, str_repeat(" ", $numIdentacao * 4), $strMensagem); | |
170 | - InfraDebug::getInstance()->gravar($strLog); | |
171 | - if(!InfraDebug::getInstance()->isBolEcho() && $bolEcho) echo sprintf("\n[%s] [PROCESSAMENTO] %s", $strDataLog, $strMensagem); | |
178 | + $this->objPenDebug->gravar($parStrMensagem, $parNumIdentacao, $parBolLogTempoProcessamento); | |
172 | 179 | } |
173 | 180 | |
174 | 181 | static function processarTarefa($strNomeTarefa, $strWorkload) | ... | ... |
rn/ReceberProcedimentoRN.php
... | ... | @@ -10,6 +10,7 @@ class ReceberProcedimentoRN extends InfraRN |
10 | 10 | private $objProcedimentoAndamentoRN; |
11 | 11 | private $documentosRetirados = array(); |
12 | 12 | public $destinatarioReal = null; |
13 | + private $objPenDebug = null; | |
13 | 14 | |
14 | 15 | public function __construct() |
15 | 16 | { |
... | ... | @@ -19,7 +20,8 @@ class ReceberProcedimentoRN extends InfraRN |
19 | 20 | $this->objProcedimentoAndamentoRN = new ProcedimentoAndamentoRN(); |
20 | 21 | $this->objReceberComponenteDigitalRN = new ReceberComponenteDigitalRN(); |
21 | 22 | |
22 | - $this->numTempoUltimoLog = null; | |
23 | + //Configuração dos logs de debug de processamento | |
24 | + $this->objPenDebug = DebugPen::getInstance(); | |
23 | 25 | } |
24 | 26 | |
25 | 27 | protected function inicializarObjInfraIBanco() |
... | ... | @@ -137,7 +139,7 @@ class ReceberProcedimentoRN extends InfraRN |
137 | 139 | $numTempoInicialValidacao = microtime(true); |
138 | 140 | $this->objReceberComponenteDigitalRN->validarIntegridadeDoComponenteDigital($arrAnexosComponentes[$key][$componentePendente], |
139 | 141 | $componentePendente, $parNumIdentificacaoTramite, $numOrdemComponente); |
140 | - $numTempoTotalValidacao = round(microtime(true) - $numTempoInicialValidacao, 2); | |
142 | + $numTempoTotalValidacao = microtime(true) - $numTempoInicialValidacao; | |
141 | 143 | $numVelocidade = round($numTamanhoArquivoKB / $numTempoTotalValidacao, 2); |
142 | 144 | $this->gravarLogDebug("Tempo total de validação de integridade: {$numTempoTotalValidacao}s ({$numVelocidade} kb/s)", 7); |
143 | 145 | } |
... | ... | @@ -1936,24 +1938,8 @@ class ReceberProcedimentoRN extends InfraRN |
1936 | 1938 | } |
1937 | 1939 | } |
1938 | 1940 | |
1939 | - private function gravarLogDebug($strMensagem, $numIdentacao=0, $bolLogTempoProcessamento=true) | |
1941 | + private function gravarLogDebug($parStrMensagem, $parNumIdentacao=0, $parBolLogTempoProcessamento=true) | |
1940 | 1942 | { |
1941 | - $strDataLog = date("d/m/Y H:i:s"); | |
1942 | - $strLog = sprintf("[%s] [PROCESSAMENTO] %s %s", $strDataLog, str_repeat(" ", $numIdentacao * 4), $strMensagem); | |
1943 | - | |
1944 | - //Registro de tempo de processamento desde último log | |
1945 | - if($bolLogTempoProcessamento){ | |
1946 | - $numTempoFinal = microtime(true); | |
1947 | - if(is_null($this->numTempoUltimoLog)){ | |
1948 | - //Inicializa contador de tempo de processamento | |
1949 | - $this->numTempoUltimoLog = $numTempoFinal; | |
1950 | - } else { | |
1951 | - $numTempoProcessamento = round($numTempoFinal - $this->numTempoUltimoLog, 2); | |
1952 | - $strLog .= " [tempo: +{$numTempoProcessamento}s]"; | |
1953 | - $this->numTempoUltimoLog = $numTempoFinal; | |
1954 | - } | |
1955 | - } | |
1956 | - | |
1957 | - InfraDebug::getInstance()->gravar($strLog); | |
1943 | + $this->objPenDebug->gravar($parStrMensagem, $parNumIdentacao, $parBolLogTempoProcessamento); | |
1958 | 1944 | } |
1959 | 1945 | } | ... | ... |
rn/ReceberReciboTramiteRN.php
... | ... | @@ -6,13 +6,14 @@ class ReceberReciboTramiteRN extends InfraRN |
6 | 6 | private $objProcessoEletronicoRN; |
7 | 7 | private $objInfraParametro; |
8 | 8 | private $objProcedimentoAndamentoRN; |
9 | + private $objPenDebug = null; | |
9 | 10 | |
10 | 11 | public function __construct() |
11 | 12 | { |
12 | - parent::__construct(); | |
13 | - | |
14 | - $this->objProcessoEletronicoRN = new ProcessoEletronicoRN(); | |
15 | - $this->objProcedimentoAndamentoRN = new ProcedimentoAndamentoRN(); | |
13 | + parent::__construct(); | |
14 | + $this->objProcessoEletronicoRN = new ProcessoEletronicoRN(); | |
15 | + $this->objProcedimentoAndamentoRN = new ProcedimentoAndamentoRN(); | |
16 | + $this->objPenDebug = DebugPen::getInstance(); | |
16 | 17 | } |
17 | 18 | |
18 | 19 | protected function inicializarObjInfraIBanco() |
... | ... | @@ -33,7 +34,7 @@ class ReceberReciboTramiteRN extends InfraRN |
33 | 34 | //Registra falha em log de debug mas não gera rollback na transação. |
34 | 35 | //O rollback da transação poderia deixar a situação do processo inconsistênte já que o Barramento registrou anteriormente que o |
35 | 36 | //recibo já havia sido obtido. O erro no fechamento não provoca impacto no andamento do processo |
36 | - InfraDebug::getInstance()->gravar("Processo $strProtocoloFormatado não está aberto na unidade."); | |
37 | + $this->objPenDebug->gravar("Processo $strProtocoloFormatado não está aberto na unidade."); | |
37 | 38 | } |
38 | 39 | |
39 | 40 | $arrObjAtributoAndamentoDTO = array(); | ... | ... |