Skip to content
Frank Corso edited this page Aug 6, 2020 · 3 revisions

Popup Maker has a built-in logging system that is used to log messages to the pum-debug.log file which is kept in the uploads directory.

How the system works

Within Popup Maker, there is the PUM_Utils_Logging which can be found in https://github.com/PopupMaker/Popup-Maker/blob/master/classes/Utils/Logging.php. This class handles all of the logging functionality.

Interacting with the logging system starts with call an instance:

PUM_Utils_Logging::instance();

The constructor calls the init method which prepares the filename and path. It additionally truncates the file if the file is larger than 1MB. https://github.com/PopupMaker/Popup-Maker/blob/master/classes/Utils/Logging.php#L59

Once created, writing a message to the log is handled by the log method. https://github.com/PopupMaker/Popup-Maker/blob/master/classes/Utils/Logging.php#L88.

For example:

PUM_Utils_Logging::instance()->log( 'Some random error message' );

There is also the log_unique method which only adds the message if it does not already exist in the logs. Once checked, this calls the log method.

Lastly, there is the log_deprecated_notice method which takes a function name, the version it was deprecated, and optionally the recommended replacement. Once the message is formatted, this calls the log_unique method.

All of those methods eventually lead to the write_to_log method. As long as the PUM_DISABLE_LOGGING is not defined or not set to true, the method will retrieve the contents of the log file, append the new message, and then save back to the log file. The logged message will include a timestamp for when it was added.

To retrieve the contents, we use the get_log method, and to clear the file we use clear_log.

The Error Log Tools tab

To allow admins to view the contents, we have the "Error Log" tab available in the "Tools" page.

The tab gets added within the PUM_Admin_Tools class: https://github.com/PopupMaker/Popup-Maker/blob/master/classes/Admin/Tools.php#L124

The errorlog_display controls the contents of tab which calls the display_error_log method to display the logs inside a <pre> element using the get_log of PUM_Utils_Logging.

The tab also contains a button to empty the log. Once clicked, the error_log_empty gets called which then calls the clear_log of PUM_Utils_Logging