Skip to content

Commit

Permalink
feat: adding tools and fix ata
Browse files Browse the repository at this point in the history
  • Loading branch information
igorgoncalves committed Jan 3, 2025
1 parent b46b408 commit 0c9fe60
Show file tree
Hide file tree
Showing 10 changed files with 2,293 additions and 404 deletions.
46 changes: 21 additions & 25 deletions app/components/utils/TLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,37 @@

class TLog extends CApplicationComponent {

public static function info($message, $data = null){
$route = Yii::app()->controller->id . "/". Yii::app()->controller->action->id;
$builderMessage = "[$route]: $message" ;
// Função auxiliar para gerar a mensagem de log
private static function generateLogMessage($message, $data = null) : string {
$module = Yii::app()->controller->module ? Yii::app()->controller->module->id . '/' : '';

if(isset($data)){
$builderMessage .= PHP_EOL . CVarDumper::dumpAsString($data);
}

$route = $module . Yii::app()->controller->id . "/" . Yii::app()->controller->action->id;
$builderMessage = "[$route]: $message";

Yii::log($builderMessage, CLogger::LEVEL_INFO, 'application');
if (isset($data)) {
// Garante que dados sejam codificados como JSON
$builderMessage .= ' | ' . CJSON::encode($data);
}

return $builderMessage;
}

public static function warning($message, $data = null){
$route = Yii::app()->controller->id . "/". Yii::app()->controller->action->id;
$builderMessage = "[$route]: $message" ;

if(isset($data)){
$builderMessage .= PHP_EOL . CVarDumper::dumpAsString($data);
}
// Método para log de nível info
public static function info($message, $data = null) {
$builderMessage = self::generateLogMessage($message, $data);
Yii::log($builderMessage, CLogger::LEVEL_INFO, 'application');
}

// Método para log de nível warning
public static function warning($message, $data = null) {
$builderMessage = self::generateLogMessage($message, $data);
Yii::log($builderMessage, CLogger::LEVEL_WARNING, 'application');
}

public static function error($message, $data = null){
$route = Yii::app()->controller->id . "/". Yii::app()->controller->action->id;
$builderMessage = "[$route]: $message" ;

if(isset($data)){
$builderMessage .= PHP_EOL . CVarDumper::dumpAsString($data);
}

// Método para log de nível error
public static function error($message, $data = null) {
$builderMessage = self::generateLogMessage($message, $data);
Yii::log($builderMessage, CLogger::LEVEL_ERROR, 'application');
}

}

?>
4 changes: 4 additions & 0 deletions app/controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ public function actionChangeSchool()
Yii::app()->user->school = $_POST['SchoolIdentification']['inep_id'];
}

Yii::app()->cache->flush();

echo '<script>history.go(-1);</script>';
exit;
}
Expand All @@ -164,6 +166,8 @@ public function actionChangeYear()
Yii::app()->user->year = $_POST['years'];
}

Yii::app()->cache->flush();

echo '<script>history.go(-1);</script>';
exit;
}
Expand Down
77 changes: 77 additions & 0 deletions app/controllers/ToolsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

class ToolsController extends Controller
{
public $layout = 'fullmenu';

public function actionIndex()
{
$tools = array(
array('name' => 'Visualizar Logs', 'url' => Yii::app()->createUrl('tools/viewLogs')),
array('name' => 'OpCache', 'url' => Yii::app()->createUrl('tools/opcache'))

);

$this->render('index', array(
'tools' => $tools,
));
}
public function actionOpcache()
{

$this->layout = "reportsclean";
// Caminho completo para o OPcache GUI
$opcacheGuiPath = Yii::getPathOfAlias('application.extensions.opcache-gui') . '/index.php';
// Verifica se o arquivo existe
if (!file_exists($opcacheGuiPath)) {
throw new CHttpException(404, 'OPcache GUI não encontrado.');
}

// Inclui o arquivo do OPcache GUI
require_once $opcacheGuiPath;

Yii::app()->end(); // Finaliza o processamento Yii após exibir o OPcache GUI
}

public function actionViewLogs()
{
// Caminho do diretório onde os logs são armazenados
$logPath = "/app/app/runtime/" . INSTANCE . "/" . date("Y-m-d");
$logFiles = glob($logPath . '/application.log*'); // Encontra todos os arquivos de log
$logs = [];

// Ordena os arquivos para garantir que os mais recentes sejam processados primeiro
rsort($logFiles); // Ordena os arquivos de forma decrescente (do mais recente para o mais antigo)

if (!empty($logFiles)) {
foreach ($logFiles as $file) {
// Adiciona o cabeçalho com o nome do arquivo
array_unshift($logs, ["type" => "header", "file" => basename($file)]); // Coloca no início

// Abre o arquivo e lê linha por linha
$fileHandle = fopen($file, 'r');
if ($fileHandle) {
while (($line = fgets($fileHandle)) !== false) {
array_unshift($logs, ["type" => "log", "line" => $line]); // Coloca no início
}
fclose($fileHandle);
}
}
}

$dataProvider = new CArrayDataProvider($logs, array(
'id' => 'log',
'pagination' => array(
'pageSize' => 50, // Exibir 50 linhas por página
),
));

$this->render('viewLogs', array(
'dataProvider' => $dataProvider,
));
}


}


Loading

0 comments on commit 0c9fe60

Please sign in to comment.