How can errors, specific to a given plugin, be logged to an error_log file contained within the plugin root folder itself?

Examples:

  • Syntax errors
  • Database errors
  • Compatibility errors
  • PHP fatal errors
  • Ajax request errors

Similar to the /wp-content/debug.log file enable when WP_DEBUG_LOG is defined as true in the wp-config.php file (albeit specifically for plugins with its concerns separated from any other general error unrelated to the plugin itself).

Research:

Debugging Plugins section in the official documentation of the Codex refers to using 3rd party plugins to debug 3rd party plugins.

Don’t Develop Without Debuggingby Smashing Magazine refers to site-wide general debugging.

Plugin Handbook appears to layout no specific guidelines.

1 Answer
1

By setting the second argument to 3 for error_log:

$pluginlog = plugin_dir_path(__FILE__).'debug.log';
$message="SOME ERROR".PHP_EOL;
error_log($message, 3, $pluginlog);

http://php.net/manual/en/function.error-log.php

Leave a Reply

Your email address will not be published. Required fields are marked *