Last active
February 19, 2016 04:29
-
-
Save userabuser/e5dffe4185733b96a55a to your computer and use it in GitHub Desktop.
Dirty little logger function for WordPress (mu-plugins)
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
/** | |
* By pass the need to define up to three constants, WP_DEBUG, WP_DEBUG_LOG | |
* and WP_DEBUG_DISPLAY by setting the error_log ini value so that any time | |
* logger() is called data is written to debug.log. | |
*/ | |
ini_set('log_errors', 1); | |
ini_set('error_log', WP_CONTENT_DIR . '/debug.log'); | |
/** | |
* Takes an arbitrary amount of arguments, the first of which | |
* should typically be an identifying message or key marker | |
* that you can use to identify your output withing the debug.log | |
* file. | |
*/ | |
if ( ! function_exists('logger') ) { | |
function logger() { | |
$args = func_get_args(); | |
$msg = array_shift($args); | |
if ( is_array($args) || is_object($args) ) { | |
$data = array_merge(array('message' => $msg), $args); | |
if ( in_array(':export', $args) ) { | |
ob_start(); | |
var_dump($data); | |
$data = ob_get_clean(); | |
} | |
error_log( var_export($data, true) ); | |
} else { | |
error_log($args, true); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment