Skip to content

Instantly share code, notes, and snippets.

@lgedeon
Created January 20, 2022 12:59
Show Gist options
  • Save lgedeon/acbb7217d0fe692821c820829d8b2a55 to your computer and use it in GitHub Desktop.
Save lgedeon/acbb7217d0fe692821c820829d8b2a55 to your computer and use it in GitHub Desktop.
My favorite logger so far
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