Log Your Own Debug Messages in WordPress debug.log

Log your own debug messages within a WordPress plugin or theme. This will let you record your own information into the debug.log file in WordPress. First, place this function within your plugin or theme:

/**
 * Log my own debug messages
 */
function isa_log_my_messages( $message ) {
	if (WP_DEBUG === true) {
		if ( is_array( $message) || is_object( $message ) ) {
			error_log( print_r( $message, true ) );
		} else {
			error_log( $message );
		}
	}
}

Then use the function in your code wherever you want to make an entry into the debug log:

isa_log_my_messages( "This is a sample message" );

You can log arrays and objects, as well. For example:

isa_log_my_messages( $some_object );
isa_log_my_messages( $some_array );

Note that this function will only log entries if you have set “WP_DEBUG” to true.

Questions and Comments are Welcome

Your email address will not be published. All comments will be moderated.

Please wrap code in "code" bracket tags like this:

[code]

YOUR CODE HERE 

[/code]