First Commit
This commit is contained in:
Executable
+41
@@ -0,0 +1,41 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user