ActionScheduler_DBLogger::log
Add a record to an action log.
Method of the class: ActionScheduler_DBLogger{}
No Hooks.
Returns
Int. The log entry ID.
Usage
$ActionScheduler_DBLogger = new ActionScheduler_DBLogger(); $ActionScheduler_DBLogger->log( $action_id, $message, ?DateTime $date );
- $action_id(int) (required)
- Action ID.
- $message(string) (required)
- Message to be saved in the log entry.
- ?DateTime $date
- .
Default: null
ActionScheduler_DBLogger::log() ActionScheduler DBLogger::log code WC 10.3.5
public function log( $action_id, $message, ?DateTime $date = null ) {
if ( empty( $date ) ) {
$date = as_get_datetime_object();
} else {
$date = clone $date;
}
$date_gmt = $date->format( 'Y-m-d H:i:s' );
ActionScheduler_TimezoneHelper::set_local_timezone( $date );
$date_local = $date->format( 'Y-m-d H:i:s' );
/** @var \wpdb $wpdb */ //phpcs:ignore Generic.Commenting.DocComment.MissingShort
global $wpdb;
$wpdb->insert(
$wpdb->actionscheduler_logs,
array(
'action_id' => $action_id,
'message' => $message,
'log_date_gmt' => $date_gmt,
'log_date_local' => $date_local,
),
array( '%d', '%s', '%s', '%s' )
);
return $wpdb->insert_id;
}