42 lines
1.2 KiB
PHP
Executable File
42 lines
1.2 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
class LogsClearCommand extends Command
|
|
{
|
|
protected static $defaultName = 'logs:clear';
|
|
protected static $defaultDescription = 'Limpa os arquivos de log do sistema';
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
|
{
|
|
$logDir = dirname(__DIR__, 3) . '/logs';
|
|
|
|
if (!is_dir($logDir)) {
|
|
$output->writeln('<error>Diretório de logs não encontrado.</error>');
|
|
return Command::FAILURE;
|
|
}
|
|
|
|
$files = glob($logDir . '/*.log');
|
|
|
|
if (empty($files)) {
|
|
$output->writeln('<info>Nenhum arquivo de log para limpar.</info>');
|
|
return Command::SUCCESS;
|
|
}
|
|
|
|
foreach ($files as $file) {
|
|
$fileName = basename($file);
|
|
if (unlink($file)) {
|
|
$output->writeln("<info>Arquivo de log '{$fileName}' removido.</info>");
|
|
} else {
|
|
$output->writeln("<error>Falha ao remover o arquivo '{$fileName}'.</error>");
|
|
}
|
|
}
|
|
|
|
return Command::SUCCESS;
|
|
}
|
|
}
|