Skip to content

Instantly share code, notes, and snippets.

@wakasann
Last active September 9, 2016 03:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wakasann/5fb7ce4db435eb0054d036462e626ee0 to your computer and use it in GitHub Desktop.
Save wakasann/5fb7ce4db435eb0054d036462e626ee0 to your computer and use it in GitHub Desktop.
wordpress write debug log
<?php
/**
* Plugin Name: Write log
* Plugin URI:
* Description: Writes a message to /wp-content/debug.log if debugging is turned on.
* Version: 1.0.0-dev
* Author: wakasann
* Author URI: http://wakasann.github.io/
* Requires at least: 4.4
* Tested up to: 4.5
*
*/
if ( ! function_exists('write_log')) {
/**
* write log to debug.log file
*
* Writes a message to /wp-content/debug.log if debugging is turned on.
*
* @link https://gist.github.com/theantichris/3219824
* @link https://www.elegantthemes.com/blog/tips-tricks/using-the-wordpress-debug-log
* @link http://www.stumiller.me/sending-output-to-the-wordpress-debug-log/
*
* @param mixed $message What to output to the log file
*
* @return void
*/
function write_log ( $log ) {
if ( true === WP_DEBUG ) {
if ( is_array( $log ) || is_object( $log ) ) {
error_log( print_r( $log, true ) );
} else {
error_log( $log );
}
}
}
}
/* 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
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment