Last active
July 26, 2018 19:03
-
-
Save evanre/3035881fff6a08124a1699d7d68643d4 to your computer and use it in GitHub Desktop.
Simple debug trace to wp-content/debug.log
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
/** | |
* 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