wp-user-frontend
wp-user-frontend copied to clipboard
WPUF logger added
A new function is introduced where we can log our messages in a specific file. It will help us debug cron jobs, form settings, payment info etc. Calling a simple function wpuf_log( $message )
will do the trick. It will store a log with the current date time in the wp-content/uploads/wpuf-logs/
directory. A new log file will be created for each day and all the log files older than 60 days will be removed.
How to use
Simply calling wpuf_log( $message )
will store the log message with datetime. This function also have 2 others optional parameter to pass. So the three parameters are:
$message [string] The message to log
$level [string]
The log level. Default info
Description of levels: 'emergency': System is unusable. 'alert': Action must be taken immediately. 'critical': Critical conditions. 'error': Error conditions. 'warning': Warning conditions. 'notice': Normal but significant condition. 'info': Informational messages. 'debug': Debug-level messages.
$log_file [string|resource] Optional parameter to pass the log file. The log will be written in this file instead of the default log file.
A basic use:
wpuf_log( sprintf(
'Post form: %d is set to expire after %s %s. Expired post status: %s',
$data['form_id'],
$time,
$type,
$status
));
Will store a log message like:
[12/Jul/2022:08:07:13 +0000] INFO: Post form: 973 is set to expire after 2 day. Expired post status: draft
Hooks Introduced
wpuf_log_directory
[filter]: The default log directory is wp-content/uploads/wpuf-logs/
. We can change it using this filter.
wpuf_log_file_name
[filter]: We can change the log file name entirely using this filter.
wpuf_formatted_log_message
[filter]: The default log format is [%datetime%] %level%: %message%\n
. With this filter we will get the formatted log message.
wpuf_logger_expiration_days
[filter]: Log file will be deleted after 60 days. We can change it using this filter.