Skip to content

Commit

Permalink
Adds cron events logging.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Lannoy committed Aug 25, 2021
1 parent dc963a1 commit ab0c889
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- New logger to send events to New Relic as NR-Logs.
- New logger to send metrics to New Relic.
- New logger to send traces to New Relic.
- All cron-related events are now logged (schedule, unschedule and clear).
- Logos for Action Scheduler and WooCommerce in events list and viewer.
- Logos for BuddyPress in events list and viewer.
- Logos for standard, Amelia and Forminator Stripe gateways in events list and viewer.

### Changed
- Designed has been improved pour the logger selector.
- Designed has been improved for the logger selector.

## [3.1.0] - 2021-08-11

Expand Down
50 changes: 50 additions & 0 deletions includes/listeners/class-corelistener.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ protected function launch() {
add_filter( 'wp', [ $this, 'wp' ], 10, 1 );
// Rest API
add_filter( 'http_api_debug', [ $this, 'http_api_debug' ], 10, 5 );
// Cron
add_filter( 'schedule_event', [ $this, 'schedule_event' ], PHP_INT_MAX, 1 );
add_filter( 'pre_clear_scheduled_hook', [ $this, 'pre_clear_scheduled_hook' ], PHP_INT_MAX, 5 );
add_filter( 'pre_unschedule_hook', [ $this, 'pre_unschedule_hook' ], PHP_INT_MAX, 4 );
// Aplications Passwords
add_action( 'wp_create_application_password', [ $this, 'wp_create_application_password' ], 10, 4 );
add_action( 'wp_update_application_password', [ $this, 'wp_update_application_password' ], 10, 3 );
Expand Down Expand Up @@ -1299,6 +1303,52 @@ public function http_api_debug( $response, $context, $class, $request, $url ) {
}
}

/**
* "schedule_event" event.
*
* @since 3.2.0
*/
public function schedule_event( $event = null ) {
if ( $event && is_object( $event ) && property_exists( $event, 'hook' ) && property_exists( $event, 'schedule' ) && property_exists( $event, 'timestamp' ) ) {
if ( $event->schedule ) {
$this->logger->debug( sprintf( 'The recurring event "%s" has been scheduled to "%s".', $event->hook, $event->schedule ) );
} else {
$this->logger->debug( sprintf( 'The single event "%s" has been (re)scheduled and will be executed %s.', $event->hook, ( 0 === $event->timestamp - time() ? 'immediately' : sprintf( 'in %d seconds', $event->timestamp - time() ) ) ) );
}
} else {
$this->logger->notice( 'A plugin prevented an event to be scheduled or rescheduled.' );
}
return $event;
}

/**
* "pre_clear_scheduled_hook" event.
*
* @since 3.2.0
*/
public function pre_clear_scheduled_hook( $pre, $hook, $args = null, $wp_error = null ) {
if ( is_null( $pre ) ) {
$this->logger->info( sprintf( 'The "%s" event will be cleared.', $hook ) );
} else {
$this->logger->notice( sprintf( 'A plugin prevented the "%s" event to be cleared.', $hook ) );
}
return $pre;
}

/**
* "pre_unschedule_hook" event.
*
* @since 3.2.0
*/
public function pre_unschedule_hook( $pre, $hook, $wp_error = null ) {
if ( is_null( $pre ) ) {
$this->logger->info( sprintf( 'The "%s" event will be unscheduled.', $hook ) );
} else {
$this->logger->notice( sprintf( 'A plugin prevented the "%s" event to be unscheduled.', $hook ) );
}
return $pre;
}

/**
* "wp_create_application_password" event.
*
Expand Down

0 comments on commit ab0c889

Please sign in to comment.