Why you should write log file for your WordPress plugin processes?

Often, WordPress plugin users come for support on WordPress.org, saying that this feature is not working. At that time, the plugin author should debug the plugin processes. According to WordPress forum policy, the plugin author can’t ask for WordPress site admin dashboard or FTP credential access. At this time, the plugin author gives different suggestions for tweaks, but they will not work. Now, the plugin author has a dilemma about what to do. At that time, the debug log is the friend of the plugin author and the plugin support personnel. The plugin support personnel can ask for the debug log, and it is legal according to WordPress support forum policy. Often complex processing popular plugins write the debug log.

What ought to write the debug log?

The plugin should write what it is processing. The backup plugin writes a new log file for a backup, restore, and migration. The plugin should write the log what it is doing. If anything is failing, it should be written in the log file. Every if-then condition should be written with a detailed description, and it will pay off you in the future.

Please avoid writing short form words like “a”, “b” and “c” etc. in the log file

How to write the debug log?

There should be a method called log() in the main plugin class. It takes arguments like text, debug level, and process id or nonce.

For each new process id or nonce, a new log file will be written.

The debug levels are of the following types:

  • Info
  • Error

Should the debug log auto cleared?

The X days old log should be cleared automatically, otherwise it consumes a lot amount of space. The X can be 30 or anything that is suitable for your plugin. To clear the log files, you can setup the WP Cron.

Leave a Reply

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

Prashant Baldha