Find and Display all error_log and .log files in WordPress

Find all PHP error_log files and log files ending with .log that reside all over your WordPress site, and display the contents of the log files. This will search your server files for any files that end with “error_log” or “.log”. For example, debug.log.

PHP is mixed with HTML here, so modify this for your needs.

function acs_rglob($pattern, $flags = 0) {
    $files = glob($pattern, $flags); 
    foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
        $files = array_merge($files, acs_rglob($dir.'/'.basename($pattern), $flags));
    }
    return $files;
}
$logs = array_merge((array)acs_rglob(ABSPATH.'*.log'), (array)acs_rglob(ABSPATH.'*error_log'));

// don't display empty log files
foreach ($logs as $k => $v) {
	if (empty(file_get_contents($v))) unset($logs[$k]);
}

// display the contents of each log file

foreach ($logs as $f) {
	?>
	<p><?php echo $f . ':'; ?></p>
	<div class="log">
	<?php
    $handle = @fopen($f,'r');
    if (false === $handle) {
    	?><p>FAILED TO OPEN THIS FILE</p><?php
    } else {
        while(($v = fgets($handle, 4096))!==false) {
            if (!trim($v)) continue;// skip blank lines
               echo $v . '<br>';
        }
        fclose($handle);			    	
    }
	?>
    </div><br><hr><br>
    <?php
}

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]