Skip to content

Instantly share code, notes, and snippets.

@evanre
Last active Jul 26, 2018
Embed
What would you like to do?
Simple debug trace to wp-content/debug.log
/**
* Simple debug trace to wp-content/debug.log
*
* @usage _log( $var );
*/
if ( ! function_exists( '_log' ) ) {
function _log() {
$args = func_get_args();
// loop
foreach ( $args as $arg ) {
$arg = _log_check_value( $arg );
// Print each item separately
if ( true == WP_DEBUG ) {
error_log( $arg );
} else {
ob_start();
echo '[' . date( 'd-M-Y h:i:s T' ) . '] ' . $arg . '\r\n';
file_put_contents( ABSPATH . 'wp-content/debug.log', ob_get_contents(), FILE_APPEND );
ob_end_clean();
}
}
}
function _log_check_value( $arg ) {
if ( is_array( $arg ) || is_object( $arg ) ) {
$arg = print_r( $arg, true );
} elseif ( is_bool( $arg ) ) {
$arg = ( $arg ? 'true' : 'false' ) . ' (bool)';
}
return $arg;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment