public
Last active

Function to output a message to WordPress debug.log.

  • Download Gist
print_to_log.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/**
* Writes a message to /wp-content/debug.log if debugging is turned on.
*
* @param mixed $message What to output to the log file
*
* @return void
*/
function print_to_log( $message )
{
if ( true === WP_DEBUG ) {
if ( is_array( $message ) || is_object( $message ) ) {
error_log( print_r( $message, true ) );
} else {
error_log( $message );
}
}
}
wp-config.php
PHP
1 2 3 4 5
/* Add the following lines to wp-config.php to turn on debugging. */
define( 'WP_DEBUG', true ); // Turn debugging ON
define( 'SAVEQUERIES', true );
define( 'WP_DEBUG_DISPLAY', false ); // Turn forced display OFF
define( 'WP_DEBUG_LOG', true ); // Turn logging to wp-content/debug.log ON

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.