Write a debug log to the WP uploads directory. Use tail -f in a terminal to watch for changes on the fly
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
<?php | |
/** | |
* Write a debug log. | |
* | |
* @param mixed $msg A message to log. | |
*/ | |
function sitecare_debug_log( $msg = null ) { | |
if ( ! is_string( $msg ) ) { | |
$msg = print_r( $msg, true ); | |
} | |
$upload_dir = wp_upload_dir(); | |
$log_dir = "{$upload_dir['basedir']}/logs/"; | |
$log_file = "{$log_dir}sitecare-debug-log.txt"; | |
if ( ! is_dir( $log_dir ) ) { | |
wp_mkdir_p( $log_dir ); | |
} | |
$open_file = fopen( $log_file, 'a+' ); | |
if ( false !== $open_file ) { | |
if ( null === $msg ) { | |
fwrite( $open_file, date( "\r\nY-m-d H:I:s:\r\n" ) ); | |
} else { | |
fwrite( $open_file, date( 'Y-m-d H:i:s - ' ) . $msg . "\r\n" ); | |
} | |
} | |
fclose( $open_file ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment