<?php

namespace App\Controllers;

class LogTest extends BaseController
{
    public function index()
    {
        log_message('error', '===== WEB LOG TEST ===== ' . date('Y-m-d H:i:s'));
        log_message('info', 'Info from web');
        log_message('debug', 'Debug from web');
        
        $logFile = WRITEPATH . 'logs/log-' . date('Y-m-d') . '.log';
        
        echo "ENVIRONMENT: " . ENVIRONMENT . "<br>";
        echo "Log file: " . $logFile . "<br>";
        echo "Exists: " . (file_exists($logFile) ? 'YES' : 'NO') . "<br>";
        echo "Writable: " . (is_writable(dirname($logFile)) ? 'YES' : 'NO') . "<br>";
        
        if (file_exists($logFile)) {
            echo "<h3>Last 20 lines:</h3>";
            echo "<pre>";
            echo htmlspecialchars(shell_exec('tail -20 ' . escapeshellarg($logFile)));
            echo "</pre>";
        }
    }
}
