EchoFool Posted June 2, 2009 Share Posted June 2, 2009 Is it possible in php to grab Apache logs from your server to be displayed in a php page? I been wanting to work out how so i don't have to constantly keep logging into cpanel to read them! Any one ever heard of this done? Link to comment https://forums.phpfreaks.com/topic/160577-grab-apache-logs/ Share on other sites More sharing options...
BobcatM Posted June 2, 2009 Share Posted June 2, 2009 Format issue. Link to comment https://forums.phpfreaks.com/topic/160577-grab-apache-logs/#findComment-847460 Share on other sites More sharing options...
BobcatM Posted June 2, 2009 Share Posted June 2, 2009 Here is the one I used at one time. <?php exec('tail /usr/local/apache/logs/error_log', $output); ?> <Table border="1"> <tr> <th>Date</th> <th>Type</th> <th>Client</th> <th>Message</th> </tr> <? foreach($output as $line) { // sample line: [Wed Oct 01 15:07:23 2008] [error] [client 76.246.51.127] PHP 99. Debugger->handleError() /home/gsmcms/public_html/central/cake/libs/debugger.php:0 preg_match('~^\[(.*?)\]~', $line, $date); if(empty($date[1])) { continue; } preg_match('~\] \[([a-z]*?)\] \[~', $line, $type); preg_match('~\] \[client ([0-9\.]*)\]~', $line, $client); preg_match('~\] (.*)$~', $line, $message); ?> <tr> <td><?=$date[1]?></td> <td><?=$type[1]?></td> <td><?=$client[1]?></td> <td><?=$message[1]?></td> </tr> <? } ?> </table> Link to comment https://forums.phpfreaks.com/topic/160577-grab-apache-logs/#findComment-847462 Share on other sites More sharing options...
EchoFool Posted June 2, 2009 Author Share Posted June 2, 2009 Thanks! Though i get this error: PHP Warning: exec() has been disabled for security reasons in errors.php on line 2 Is there a safer function to use? Link to comment https://forums.phpfreaks.com/topic/160577-grab-apache-logs/#findComment-847466 Share on other sites More sharing options...
EchoFool Posted June 2, 2009 Author Share Posted June 2, 2009 bump Link to comment https://forums.phpfreaks.com/topic/160577-grab-apache-logs/#findComment-847808 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.