• Welcome to Simple Machines Community Forum. Please login or sign up.
December 07, 2021, 01:38:14 PM

News:

SMF 2.0.18 has been released! Please update. Read more.


Writing to the php-error-log with var_dump

Started by aegersz, June 11, 2021, 01:39:53 AM

Previous topic - Next topic

aegersz

from: https://www.justinsilver.com/technology/writing-to-the-php-error_log-with-var_dump-and-print_r/
A little debugging tip, if not aforementioned:

function var_error_log( $object=null ){
    ob_start();                    // start buffer capture
    var_dump( $object );           // dump the values
    $contents = ob_get_contents(); // put the buffer into a variable
    ob_end_clean();                // end capture
    error_log( $contents );        // log contents of the result of var_dump( $object )
}

$object = $variableToLog;
var_error_log( $object );
The configuration of my Linux VPS (SMF 2.0 with 160+ mods & some assorted manual tweaks) can be found here and notes on my mods can be found here (warning: those links will take you to a drug related forum). My (House) music DJ dedication page is here

live627

This is quite neat. One pitfall, though, is that xdebug adds a html transform and trims large or deep arrays. I use var_export to get the entire array.

error_log(var_export($message, true));

To get it into SMF's log is very similar

log_error(var_export($message, true));https://support.simplemachines.org/function_db/index.php?action=view_function;id=42

aegersz

Thanks for the tips - writing to a file is preferable to writing to the screen, I discovered ... I am only a novice but looking into variables has helped me with debugging my huge amounts of mod interactions.
The configuration of my Linux VPS (SMF 2.0 with 160+ mods & some assorted manual tweaks) can be found here and notes on my mods can be found here (warning: those links will take you to a drug related forum). My (House) music DJ dedication page is here

Advertisement: