Skip to content

Instantly share code, notes, and snippets.

@evanre
Last active July 26, 2018 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save evanre/3035881fff6a08124a1699d7d68643d4 to your computer and use it in GitHub Desktop.
Save evanre/3035881fff6a08124a1699d7d68643d4 to your computer and use it in GitHub Desktop.
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