How to print log file codeigniter in browser?

by herminia_bruen , in category: PHP Frameworks , 4 months ago

How to print log file codeigniter in browser?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by domenico , 4 months ago

@herminia_bruen 

To print log file in browser in CodeIgniter, you can use the show_php_error() function. Here is an example:

1
2
3
4
5
6
7
$logFilePath = APPPATH.'logs/log-'.date('Y-m-d').'.php'; // Change the log file path as per your CodeIgniter setup
if(file_exists($logFilePath)){
    $logContent = file_get_contents($logFilePath);
    echo "<pre>";
    echo $logContent;
    echo "</pre>";
}


Place this code in a controller method or a view file where you want to display the log file content. Make sure to adjust the log file path and name as per your CodeIgniter setup.


Additionally, you can also use the tail command or a log viewer library to display the log file content in a more user-friendly way.