-
-
Save lgedeon/acbb7217d0fe692821c820829d8b2a55 to your computer and use it in GitHub Desktop.
My favorite logger so far
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function ilog( $label = '', $value = null, $dump = false ) { | |
static $logs = []; | |
if ( true === $dump ) { | |
echo "\n<h1>Log Report</h1>\n"; | |
foreach ( $logs as $log ) { | |
echo "<br/>\n{$log['label']}: "; | |
var_export( $log['value'] ); | |
echo "\n<br/>"; | |
} | |
} else { | |
$logs[] = [ | |
'label' => $label, | |
'value' => $value, | |
]; | |
} | |
} | |
add_action( | |
'wp_footer', | |
function () { | |
ilog( true, true, true ); | |
} | |
); | |
add_action( | |
'admin_footer', | |
function () { | |
ilog( true, true, true ); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment