Solved

Error logs at folder level

Posted on 2014-09-23
3
253 Views
Last Modified: 2014-09-24
Hi All,

On some of the shared hosting websites, I noticed that (due to some configurations set by them), the error.log is generated in the same folder where the error occured. This is a nice thing and I am wondering if we can implement the same on our own webserver setup.

I know, we can enable logging in vitualhost config or .htaccess, but it's practially not possible to keep creating htaccess files for each folder that gets added to the code etc..

Any thoughts?


Thanks,
Ron
0
Comment
Question by:Starquest321
  • 2
3 Comments
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40339083
In my PHP initialization settings I have error_log set to (drum roll) "error_log" and whenever errors occur, the error_log file gets created in the same directory where the errors occurred.  These three settings seem to be in play:

log_errors = On
log_errors_max_len = 1024
error_log = error_log

I put this script in my web root directory and run it to find all of the error logs, and optionally to delete them.

<?php // find_error_log.php
error_reporting(E_ALL);
ob_start();

// PUT THESE SETTINGS IN PHP.INI
// log_errors = On
// log_errors_max_len = 1024
// error_log = error_log

// PUT THIS SCRIPT IN THE WEB ROOT DIRECTORY
$path = realpath(getcwd());
$plen = strlen($path);

// THE ERROR LOG FILE NAME
$signal = strrev('error_log');


// IF THERE IS A POST-METHOD REQUEST TO DELETE THE ERROR LOG
if (!empty($_POST['log']))
{
    // MAKE SURE WE ONLY UNLINK THE ERROR LOG FILE
    $test = strrev($_POST['log']);
    if (strpos($test, $signal) === 0)
    {
        unlink($path . $_POST['log']);
        echo '<h3>' . $_POST['log'] . ' Discarded</h3>';
    }
}


// SEE http://php.net/manual/en/class.recursivedirectoryiterator.php#85805
$objs = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
foreach($objs as $name => $obj)
{
    // PROCESS THE ERROR LOG ONLY
    $test = strrev($name);
    if (strpos($test, $signal) === 0)
    {
        $name = substr($name, $plen);
        $form = <<<EOD
<form method="post" style="margin:0; padding:0; display:inline;!important">
<b>$name</b>
<input type="submit" value="Discard?" />
<input type="hidden" name="log" value="$name" />
</form>
EOD;
        echo $form;

        // SHOW THE CONTENTS OF THE ERROR LOG
        echo '<pre>';
        print_r(file_get_contents($path . $name));
        echo "</pre>";
    }
}

$out = ob_get_contents();
if (empty($out)) echo '<h3>Good News! No error_log found.</h3>';

Open in new window

0
 

Author Closing Comment

by:Starquest321
ID: 40341240
Thanks, that worked
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40341310
Gr8!  Thanks for the points, ~Ray
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
hbo knew my windows software 4 62
Currency in SQL? 2 30
Help in good tutorials for PHP, HTML and CSS 6 40
Showing multiple maps using PHP and Google Maps 8 19
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
1. Introduction As many people are interested in Linux but not as many are interested or knowledgeable (enough) to install Linux on their system, here is a safe way to try out Linux on your existing (Windows) system. The idea is that you insta…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question