Created
September 29, 2016 18:25
-
-
Save robneu/74cbb63e317b2e0a08a6aef54c118b74 to your computer and use it in GitHub Desktop.
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