feature-request : html + css logging in apache logs (example for the rest of the unix community too)

php.internals

Rene Veerman

10 years ago
Hi. Once again, thanks for keeping PHP free to use and so widely and easily installed.. I have another feature request (sent earlier tonight).. I quite often, much more than i like, *need* a stacktrace and *proper* variable listings for each function called in PHP when it barfs out nothing more than an apache error log entry.. And can we please show such entries in the browser *as well as the apache log*? Or if nothing else, *just* in the browser? Rather than going "all the way" and making variable contents (which can grow quite large) collapsable and shit *right away*, you could simply add the right <span> and <p> class="" names and supply a CSS file. I use it in all error handling that does make it to set_error_handler(myHandler), and that really is what makes things like my obfuscator (also posted about to the php-general@lists.php.net earlier tonight) possible. And taking things that far allows guys like me to provide you with a collapsable large-JSON-decoding viewer addon for such logfiles later (rest assured that that'll get done once you do this for me).. i call it jsonViewer and i should have it back up at http://seductiveapps.com/tools/json (or /jsonViewer) once the obfuscator is fully done in a few weeks, at most.. if you want me to build (and opensource) things like that true-obfuscator and my JSON scalable database architecture using just apache2+ and php5+, it would really cut my development time in more than half if you could add "all of this" (it's deadsimple and a few hours work imo) to the next versions of PHP (and please make it the default, you can include sample CSS or read in a CSS file that you set in php.ini (comment on how to do this in the logfile html please)).. see https://github.com/seductiveapps/folderDB/blob/master/todo.platform.txt for all relevant updates concerning these developments mentioned here.. Thanks in advance for considering and likely adopting the 2 small changes i need in the next versions of PHP.. I run ubuntu btw.. I'll be checking the php.net pages for your future updates.. If anyone can gimme a duration-to-completion for each of my requests of tonight, that'd be awesome. I'll take a "wild guess", or any serious objections that i might be able to sway out of the way..

Rene Veerman

10 years ago
nothing's better than cut-n-pasting, i knooow :) so in the next few messages i'll include my own PHP handlers.. it's 4 files, which i'll just post as ordinary text.. dunno and dont wanna test if attaching works to the entire list architecture (web caches and stuff).. On Sun, Aug 28, 2016 at 5:07 AM, Rene Veerman < rene.veerman.netherlands@gmail.com> wrote:

Rene Veerman

10 years ago
all are donated to public domain : __FILE__==='functions__internalErrorHandling.php'; <?php require_once (dirname(__FILE__).'/1.0.0/functions.php'); require_once (dirname(__FILE__).'/functions__basicErrorHandling.php'); function woError ($errCode, $errMsgOrArray) { if (is_array($errMsgOrArray)) { if (ob_get_length()>0) ob_end_flush(); ob_start(); var_dump ($errMsgOrArray); $errMsg = ob_get_clean(); } else if ( is_string($errMsgOrArray) || is_int($errMsgOrArray) || is_float($errMsgOrArray) ) { $errMsg = '' . $errMsgOrArray; } else if ( is_bool($errMsgOrArray) ) { $errMsg = ( $errMsgOrArray ? 'TRUE' : 'FALSE' ); } //echo 't1200'; //echo '<pre>'; var_dump (debug_backtrace()); echo '</pre>'; in badResult() instead trigger_error ($errMsg, $errCode); } function woBasicErrorHandler ($errno, $errstr, $errfile, $errline, $errcontext) { //echo 'woBasicErrorHandler.main:start'; $stacktrace = debug_backtrace(); $errType = wo_php_errorType_humanReadable($errno); $errSeverity = 'woErrorSeverity__error'; if (stripos($errType, 'warning')!==false) $errSeverity = 'woErrorSeverity__warning'; if (stripos($errType, 'notice')!==false) $errSeverity = 'woErrorSeverity__notice'; if (stripos($errType, 'user')!==false) $errSeverity .= ' woErrorSeverity__user'; if (stripos($errType, 'parse')!==false) $errSeverity .= ' woErrorSeverity__parse'; if (stripos($errType, 'core')!==false) $errSeverity .= ' woErrorSeverity__core'; if (stripos($errType, 'compile')!==false) $errSeverity .= ' woErrorSeverity__compile'; $html = '<div class="woError '.$errSeverity.'"><h1>webappObfuscator error</h1>' .'<p>'.$errType.' : '.$errstr.'</p>' .woBasicErrorHandler__prettyStacktrace ($stacktrace) .'</div>'; echo $html; //reportStatus (1, $html); // RV : where the F is that function?? die(); /* echo '<h1>dfo error</h1><p>'.errorType_humanReadable($errno).' : '.$errstr.'<br/>stacktrace:</p><pre>'; var_dump ($stacktrace); echo '</pre>';*/ } function woBasicErrorHandler__prettyStacktrace ($st) { global $errorsBasepath; $r = '<div class="woStacktrace">' .'<span class="woStacktrace__basePath">All filenames are under : '.$errorsBasepath.'</span><br/>'; foreach ($st as $stackNumber => $stackData) { if (array_key_exists('file', $stackData)) { $relPath = '...'.str_replace($errorsBasepath, '', $stackData['file']); } else { $relPath = '.../'; }; if (array_key_exists('line', $stackData)) { $line = '<span class="woStacktrace__line">(line '.$stackData['line'].')</span>'; } else { $line = ''; } $file = '<span class="woStacktrace__file">__FILE__ : '.$relPath.'</span> '; $function = '<span class="woStacktrace__function">'.$stackData['function'].'( ' .( array_key_exists('args',$stackData) ? woBasicErrorHandler__prettyStacktrace__arguments ($stackData['args']) : '' ) .' )</span>'; //if ($stackNumber > 0) { // ignore the call to saBasicErrorHandler() itself $r .= '<div class="woStacktrace__item">' .$file.' ' .$line.' calls ' .$function .'</div>'; //} }; $r .= '</div>'; return $r; } function woBasicErrorHandler__prettyStacktrace__arguments ($args) { $r = '<span class="woStacktrace__args">'; foreach ($args as $argIdx => $arg) { if (is_array($arg)) { $r .= '<span class="woStacktrace__arg">'.htmlentities(json_encode($arg)).'</span>'; } elseif (is_object($arg)) { $r .= '<span class="woStacktrace__arg">'.htmlentities(json_encode($arg)).'</span>'; } else { $r .= '<span class="woStacktrace__arg">'.htmlentities($arg).'</span>'; } $r .= '<span class="woStacktrace__argSeperator">, </span>'; } $r .= '</span>'; return $r; } function wo_php_json_last_error_humanReadable ($errNo) { // taken from http://php.net/manual/en/function.json-last-error.php // on 2015 July 9th, valid for php version up to 5.5.0 $errorTypes = array ( JSON_ERROR_NONE => array ( 'errorCode' => 'JSON_ERROR_NONE', 'msg' => 'No error has occurred' ), JSON_ERROR_DEPTH => array ( 'errorCode' => 'JSON_ERROR_DEPTH', 'msg' => 'The maximum stack depth has been exceeded' ), JSON_ERROR_STATE_MISMATCH => array ( 'errorCode' => 'JSON_ERROR_STATE_MISMATCH', 'msg' => 'Invalid or malformed JSON' ), JSON_ERROR_CTRL_CHAR => array ( 'errorCode' => 'JSON_ERROR_CTRL_CHAR', 'msg' => 'Control character error, possibly incorrectly encoded' ), JSON_ERROR_SYNTAX => array ( 'errorCode' => 'JSON_ERROR_SYNTAX', 'msg' => 'Syntax error' ), JSON_ERROR_UTF8 => array ( 'errorCode' => 'JSON_ERROR_UTF8', 'msg' => 'Malformed UTF-8 characters, possibly incorrectly encoded' )/*, JSON_ERROR_RECURSION => array ( 'errorCode' => 'JSON_ERROR_RECURSION', 'msg' => 'One or more recursive references in the value to be encoded' ), JSON_ERROR_INF_OR_NAN => array ( 'errorCode' => 'JSON_ERROR_INF_OR_NAN', 'msg' => 'One or more NAN or INF values in the value to be encoded' ), JSON_ERROR_UNSUPPORTED_TYPE => array ( 'errorCode' => 'JSON_ERROR_UNSUPPORTED_TYPE', 'msg' => 'A value of a type that cannot be encoded was given' )*/ ); if ($errNo===0) { $r = $errorTypes[0]; } else { $r = array_key_exists ($errNo, $errorTypes) ? $errorTypes[$errNo] : array ( 'errorCode' => 'ERROR_UNKNOWN_ERROR', 'msg' => 'json_last_error() returned a code that is unknown to fucntions__basicErrorHandling.php::wo_php_json_last_error_humanReadable()' ); }; return $r; } function wo_php_errorType_humanReadable ($errNo) { if (phpversion() < '4.0.0') { $errorTypes = array ( 1 => 'Error', 2 => 'Warning', 4 => 'Parsing Error', 8 => 'Notice', 2047 => 'E_ALL' ); } elseif (phpversion() < '5.0.0') { $errorTypes = array ( 1 => 'Error', 2 => 'Warning', 4 => 'Parsing Error', 8 => 'Notice', 16 => 'Core Error', 32 => 'Core Warning', 64 => 'Compile Error', 128 => 'Compile Warning', 256 => 'User Error', 512 => 'User Warning', 1024=> 'User Notice', 2047=> 'E_ALL' ); } elseif (phpversion() < '5.2.0') { $errorTypes = array ( 1 => 'Error', 2 => 'Warning', 4 => 'Parsing Error', 8 => 'Notice', 16 => 'Core Error', 32 => 'Core Warning', 64 => 'Compile Error', 128 => 'Compile Warning', 256 => 'User Error', 512 => 'User Warning', 1024=> 'User Notice', 2048=> 'Strict', 2047=> 'E_ALL' ); } elseif (phpversion() < '5.3.0') { $errorTypes = array ( 1 => 'Error', 2 => 'Warning', 4 => 'Parsing Error', 8 => 'Notice', 16 => 'Core Error', 32 => 'Core Warning', 64 => 'Compile Error', 128 => 'Compile Warning', 256 => 'User Error', 512 => 'User Warning', 1024=> 'User Notice', 2048=> 'Strict', 4096=> 'Recoverable', 6143=> 'E_ALL' ); } elseif (phpversion() >= '5.3.0' && phpversion() < '6.0.0') { $errorTypes = array ( 1 => 'Error', 2 => 'Warning', 4 => 'Parsing Error', 8 => 'Notice', 16 => 'Core Error', 32 => 'Core Warning', 64 => 'Compile Error', 128 => 'Compile Warning', 256 => 'User Error', 512 => 'User Warning', 1024=> 'User Notice', 2048=> 'Strict', 4096=> 'Recoverable', 8192=> 'Depracated', 16384=> 'User-level Depracated', 30719=> 'E_ALL' ); } elseif (phpversion() >= '6.0.0') { $errorTypes = array ( 1 => 'Error', 2 => 'Warning', 4 => 'Parsing Error', 8 => 'Notice', 16 => 'Core Error', 32 => 'Core Warning', 64 => 'Compile Error', 128 => 'Compile Warning', 256 => 'User Error', 512 => 'User Warning', 1024=> 'User Notice', 2048=> 'Strict', 4096=> 'Recoverable', 8192=> 'Depracated', 16384=> 'User-level Depracated', 32767=> 'E_ALL' ); } return $errorTypes[$errNo]; } ?> __FILE__==='functions__internalErrorHandling.php'; <?php /*--- this is my way of providing quality runtime debugging info (to the computerprogram itself, to developers, to end-users) and -even more important- creating robust computerprograms that can be debugged quickly when they break when they're faced with the unexpected. a future version of this will email all the *releveant* debug details to the developer(s) whenever the unexpected hits the computer program using this. draft of this extension is detailed in webappObfuscator-1.0.0.php:::webappObfuscator::readTokens() */ function badResult ($errNo, $errMeta=null) { if ( is_string($errNo) || is_array($errNo) ) { $errMeta = $errNo; $errNo = E_USER_ERROR; $errMeta['additionalError'] = 'badResult called with no $errNo as first parameter'; }; if (is_string($errMeta)) { $errMeta = array ('msg'=>$errMeta); }; //$errMeta = filterArgs($errMeta, $filterSettings); $e = array ( 'isMetaForFunc' => true, 'phpErrorClass' => $errNo, 'phpErrorType' => wo_php_errorType_humanReadable ($errNo), 'error' => $errMeta, ); $traceData = debug_backtrace(); $e['backtrace'] = $traceData;//phpFilterBacktraceData($traceData,$filterSettings); $e['globals'] = getGlobals(); //var_dump ($e); /*if (function_exists('saError')) { echo 'error handler === saError()'; saError ($errNo, $errMeta); // http://seductiveapps.com } else*/if (function_exists('woError')) { echo 'error handler === woError()'; woError ($errNo, $errMeta); } else { echo 'functions__internalErrorHandling.php::no error handler specified, var_dump-ing.<pre>'; var_dump ($e); echo '</pre>'; } return $e; } function getGlobals() { $r = array ( '$_GET' => $_GET, '$_POST' => $_POST, '$_COOKIE' => $_COOKIE ); return $r; } function good($r) { return ( is_array($r) && array_key_exists('result',$r) ); } //function &result(&$r) { function &result(&$r) { return $r['result']; } function &resultArray (&$r) { $r2 = array(); foreach ($r as $k => $v) { $r2[$k] = result($v); } return $r2; } function &goodResult(&$r) { $r2 = array ( 'isMetaForFunc' => true, 'result' => &$r ); return $r2; } ?> __FILE__==='errorHandling_css_forLightBackgrounds.css' .woError { border : 2px solid red; border-radius : 5px; padding : 5px; background : yellow; color : red; } .woStacktrace { font-size : 90%; font-weight : bold; } .woStacktrace__basePath { color : purple; } .woStacktrace__item { } .woStacktrace__file { color : navy; } .woStacktrace__function { color : #002300; } .woStacktrace__line { color : blue; } .woStacktrace__args { color : navy; font-weight : normal; } .woStacktrace__arg { color : blue; } .woStacktrace__argSeperator { color : purple; background : white; font-weight : bold; font-size : 100%; } __FILE__==='errorHandling_css_forDarkOrSemitransparentBackgrounds.css' .woError { border : 2px solid red; border-radius : 5px; padding : 5px; background : yellow; color : red; opacity : 0.767 } .woStacktrace { font-size : 90%; font-weight : bold; } .woStacktrace__basePath { color : purple; } .woStacktrace__item { } .woStacktrace__file { color : navy; } .woStacktrace__function { color : #002300; } .woStacktrace__line { color : blue; } .woStacktrace__args { color : navy; font-weight : normal; } .woStacktrace__arg { color : blue; } .woStacktrace__argSeperator { color : purple; background : white; font-weight : bold; font-size : 100%; } On Sun, Aug 28, 2016 at 5:16 AM, Rene Veerman < rene.veerman.netherlands@gmail.com> wrote:

Rene Veerman

10 years ago
eh oops, this would've maybe been easier, and allows me to update these sources in the future if and when needed.. https://github.com/seductiveapps/webappObfuscator/blob/master/webappObfuscator-1.0.0/functions__basicErrorHandling.php https://github.com/seductiveapps/webappObfuscator/blob/master/webappObfuscator-1.0.0/1.0.0/functions.php https://github.com/seductiveapps/webappObfuscator/blob/master/webappObfuscator-1.0.0/functions__internalErrorHandling.php light background css : https://github.com/seductiveapps/webappObfuscator/blob/master/webappObfuscator-1.0.0/webappObfuscator-1.0.0__ajax.css dark background css : https://github.com/seductiveapps/webappObfuscator/blob/master/webappObfuscator-1.0.0/webappObfuscator-1.0.0.css On Sun, Aug 28, 2016 at 5:21 AM, Rene Veerman < rene.veerman.netherlands@gmail.com> wrote:

Marco Pivetta

10 years ago
Are you looking for https://filp.github.io/whoops/ ? On 28 Aug 2016 5:29 a.m., "Rene Veerman" <rene.veerman.netherlands@gmail.com> wrote:

Rene Veerman

10 years ago
---------- Forwarded message ---------- From: Rene Veerman <rene.veerman.netherlands@gmail.com> Date: Sun, Aug 28, 2016 at 6:55 AM Subject: announcing public release of jsonViewer and saJSON To: php-general@lists.php.net, Internals <internals@lists.php.net> i'm gonna re-opensource these in the future anyhow for that update to the PHP error handling, so i thought it would be nice to release what i got now (should work, may need a tiny bit of work by you).. perhaps *you* can include it in the following package{3}? nice challenge perhaps..? :) https://github.com/seductiveapps/webappObfuscator/blob/ master/webappObfuscator-1.0.0/functions__basicErrorHandling.php https://github.com/seductiveapps/webappObfuscator/blob/ master/webappObfuscator-1.0.0/1.0.0/functions.php https://github.com/seductiveapps/webappObfuscator/blob/ master/webappObfuscator-1.0.0/functions__internalErrorHandling.php light background css : https://github.com/seductive apps/webappObfuscator/blob/master/webappObfuscator-1.0.0/ webappObfuscator-1.0.0__ajax.css dark background css : https://github.com/seductive apps/webappObfuscator/blob/master/webappObfuscator-1.0.0/ webappObfuscator-1.0.0.css jsonViewer provides : - a pure-PHP encoder for JSON that can handle JSON in the range of at least 100MB to maybe 1GB or more (provided you provide enough RAM ofcourse) - JS that outputs HTML that actually can view such large arrays, tested with sample JSON file[1] of 100MB in 2013 - runs in all browsers, smartphones iPhone6+ and Android 4.2+ too - initially fully-collapsed view of your data showing just the root keys - ability to open keys by clicking on them, or up to the required depth (opening-links for all up to the max depth too) - pretty colors, auto-generated from easy templates (https://github.com/ seductiveapps/saColorGradients) - a bunch of other convenient and if i may say so myself, technically impressive features URLs https://github.com/seductiveapps/jsonViewer which requires https://github.com/seductiveapps/saColorGradients and https://github.com/seductiveapps/saJSON NOTES see also my feature request to internals@lists.php.org, included here: from my master todo file at https://github.com/seductiveapps/folderDB/blob/ master/todo.platform.txt ; [3] ---------- Forwarded message ---------- From: Rene Veerman <rene.veerman.netherlands@gmail.com> Date: Sun, Aug 28, 2016 at 5:07 AM Subject: feature-request : html + css logging in apache logs (example for the rest of the unix community too) To: php-general@lists.php.net, internals@lists.php.net Hi. Once again, thanks for keeping PHP free to use and so widely and easily installed.. .,...........see https://github.com/seductiveapps/folderDB/blob/master/todo.platform.txt, search for [3] for a copy of the rest of this thread.............. and [4] for *this* email thread you're reading now.. On Sun, Aug 28, 2016 at 5:28 AM, Rene Veerman < rene.veerman.netherlands@gmail.com> wrote:

Kalle Sommer Nielsen

10 years ago
Hi 2016-08-28 5:07 GMT+02:00 Rene Veerman <rene.veerman.netherlands@gmail.com>:
> <snip> > it would really cut my development time in more than half if you could add > "all of this" (it's deadsimple and a few hours work imo) to the next > versions of PHP (and please make it the default, you can include sample CSS > or read in a CSS file that you set in php.ini (comment on how to do this in > the logfile html please))..
The best way to accomplish this is to make an RFC[1], detailing this carefully, in a well-phrased manner. Side note here, despite it may be "deadsimple", it may not be so simple to just change PHP to act as you want in the next release, PHP is used by hundreds of millions, this means that anything that can change PHP's behavior must be analyzed, and it is very rarely we do such changes in minor releases. This means that the next release, if you write an RFC, should target PHP 7.2.0. For a feature like you propose, or as to how I read it, it would most likely never become default, but if it did get implemented in PHP, it would most likely be an opt-in feature. Sorry, but it is the harsh reality. Again, like mentioned on the php-general@ list, please keep to the mailing list rules, as linked in regards to top posting, and please do not embed huge chunks of code into mails, send a link to a paste bin instead, it makes the code rather hard to read and understand properly. Thanks [1] http://wiki.php.net/rfc
-- regards, Kalle Sommer Nielsen PHP Core Developer kalle@php.net

Rene Veerman

10 years ago
Thank you. I'm not insisting it become the default, just thought it'd be handy.. As for the RFC, i'll do it after a nice long nap OK :) I dont know anything about the internals of PHP, i'm a PHP + HTML developer exclusively, but i'll try to give you some implementation suggestions in what i can make of that RFC.. On Sun, Aug 28, 2016 at 5:56 AM, Kalle Sommer Nielsen <kalle@php.net> wrote: