I created a PHP script to read the error log file in a customized visual format, but right now, I have the path to the error log file hard-coded in, which works fine for me, but I would like to find out if there's a way to pull the path to the error_log automatically so it can work on any server without further configuration.
3 Answers
You can use ini_get to obtain the error_log path in PHP.
$error_log = ini_get('error_log');
Otherwise, you'd be relegated to using something like:
<?php
ob_start();
phpinfo(INFO_CONFIGURATION);
$phpinfo = ob_get_contents();
ob_end_clean();
preg_match('#error_log</td><td\b[^>]*>(.*?)</td>#', $phpinfo, $matches);
$error_log = $matches[1];
Note that if there is no error_log set, $error_log will return:
<i>no value</i>
Comments
you can pull it from the ErrorLog Directive
2 Comments
just found this, should answer most of your questions: cyberciti.biz/faq/apache-logs
The only way to get it in PHP is by installing something like ApacheAccessor. Wouldn't call it portable though, as I've seldomly seen it installed, but wildly guessing default paths is default distro's is about your only other option.