33 lines
955 B
PHP
33 lines
955 B
PHP
<?php
|
|
|
|
namespace App\Commands;
|
|
|
|
use CodeIgniter\CLI\BaseCommand;
|
|
use CodeIgniter\CLI\CLI;
|
|
|
|
class TestLog extends BaseCommand
|
|
{
|
|
protected $group = 'Test';
|
|
protected $name = 'test:log';
|
|
protected $description = 'Test log_message function';
|
|
|
|
public function run(array $params)
|
|
{
|
|
CLI::write('Testing log_message()...', 'yellow');
|
|
|
|
log_message('error', '===== TEST LOG MESSAGE FROM CLI ===== ' . date('Y-m-d H:i:s'));
|
|
log_message('debug', 'Debug level test');
|
|
log_message('info', 'Info level test');
|
|
|
|
$logFile = WRITEPATH . 'logs/log-' . date('Y-m-d') . '.log';
|
|
|
|
CLI::write('Log file: ' . $logFile);
|
|
CLI::write('Exists: ' . (file_exists($logFile) ? 'YES' : 'NO'));
|
|
|
|
if (file_exists($logFile)) {
|
|
CLI::write('Last 10 lines:');
|
|
CLI::write(shell_exec('tail -10 ' . escapeshellarg($logFile)));
|
|
}
|
|
}
|
|
}
|