wp_cache_debug()
Add a log message to the file, if debugging is turned on
No Hooks.
Returns
null. Nothing (null).
Usage
wp_cache_debug( $message, $level );
- $message(required)
- .
- $level
- .
Default:1
wp_cache_debug() wp cache debug code WPSCache 3.1.0
function wp_cache_debug( $message, $level = 1 ) {
global $wp_cache_debug_log, $cache_path, $wp_cache_debug_ip, $wp_super_cache_debug;
static $last_message = '';
if ( $last_message == $message ) {
return false;
}
$last_message = $message;
// If either of the debug or log globals aren't set, then we can stop
if ( ! isset( $wp_super_cache_debug )
|| ! isset( $wp_cache_debug_log ) ) {
return false;
}
// If either the debug or log globals are false or empty, we can stop
if ( $wp_super_cache_debug == false
|| $wp_cache_debug_log === '' ) {
return false;
}
// If the debug_ip has been set, but it doesn't match the ip of the requester
// then we can stop.
if ( isset( $wp_cache_debug_ip )
&& $wp_cache_debug_ip !== ''
&& ( ! isset( $_SERVER['REMOTE_ADDR'] ) || $wp_cache_debug_ip !== $_SERVER['REMOTE_ADDR'] ) ) {
return false;
}
// if cache path is gone, then don't log anything
if ( empty( $cache_path ) || ! is_dir( $cache_path ) ) {
return;
}
// Log message: Date URI Message
$log_message = date( 'H:i:s' ) . ' ' . getmypid() . " {$_SERVER['REQUEST_URI']} {$message}" . PHP_EOL;
// path to the log file in the cache folder
$log_file = $cache_path . str_replace( '/', '', str_replace( '..', '', $wp_cache_debug_log ) );
if ( ! file_exists( $log_file ) && function_exists( 'wpsc_create_debug_log' ) ) {
global $wp_cache_debug_username;
if ( ! isset( $wp_cache_debug_username ) ) {
$wp_cache_debug_username = '';
}
wpsc_create_debug_log( $wp_cache_debug_log, $wp_cache_debug_username );
}
error_log( $log_message, 3, $log_file );
}