Skip to content

Instantly share code, notes, and snippets.

@facelordgists
Created March 26, 2019 19:58
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 facelordgists/6799f7d916511412bd7da93feac68a87 to your computer and use it in GitHub Desktop.
Save facelordgists/6799f7d916511412bd7da93feac68a87 to your computer and use it in GitHub Desktop.

1) Configure the wp-config.php

As follows:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

2) Add must use plugin file

Place error-logging.php in wp-content/mu-plugins folder.

3) Write stuff to the log

Like so:

write_log( "string" );
write_log( $variable_or_array );
<?php
ini_set('error_log', WP_CONTENT_DIR . '/debug.log');
ini_set('log_errors', 'On');
ini_set('display_errors', 'Off');
error_reporting(E_ERROR | E_PARSE); // Only write errors, not notices, or warnings
//error_reporting(E_ERROR | E_WARNING | E_PARSE); // if you want to also display warnings
if ( ! function_exists('write_log')) {
function write_log ( $log ) {
if ( is_array( $log ) || is_object( $log ) ) {
error_log( print_r( $log, true ) );
} else {
error_log( $log );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment