PluginProbe ʕ •ᴥ•ʔ
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / trunk
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz vtrunk
2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8 0.0.9 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.1.0 1.1.1 1.1.2 1.10.0 1.10.1 1.11.0 1.12.0 1.12.1 1.12.2 1.12.3 1.13.0 1.13.1 1.13.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.2 2.6.0
sureforms / inc / lib / action-scheduler / classes / abstracts / ActionScheduler_Logger.php
sureforms / inc / lib / action-scheduler / classes / abstracts Last commit date
ActionScheduler.php 2 years ago ActionScheduler_Abstract_ListTable.php 2 years ago ActionScheduler_Abstract_QueueRunner.php 2 years ago ActionScheduler_Abstract_RecurringSchedule.php 2 years ago ActionScheduler_Abstract_Schedule.php 2 years ago ActionScheduler_Abstract_Schema.php 2 years ago ActionScheduler_Lock.php 2 years ago ActionScheduler_Logger.php 5 months ago ActionScheduler_Store.php 2 years ago ActionScheduler_TimezoneHelper.php 2 years ago
ActionScheduler_Logger.php
178 lines
1 <?php
2
3 /**
4 * Class ActionScheduler_Logger
5 *
6 * @codeCoverageIgnore
7 */
8 abstract class ActionScheduler_Logger {
9 private static $logger = null;
10
11 /**
12 * @return ActionScheduler_Logger
13 */
14 public static function instance() {
15 if ( empty( self::$logger ) ) {
16 $class = apply_filters( 'action_scheduler_logger_class', 'ActionScheduler_wpCommentLogger' );
17 self::$logger = new $class();
18 }
19 return self::$logger;
20 }
21
22 /**
23 * @param string $action_id
24 * @param string $message
25 * @param DateTime $date
26 *
27 * @return string The log entry ID
28 */
29 abstract public function log( $action_id, $message, DateTime $date = null );
30
31 /**
32 * @param string $entry_id
33 *
34 * @return ActionScheduler_LogEntry
35 */
36 abstract public function get_entry( $entry_id );
37
38 /**
39 * @param string $action_id
40 *
41 * @return ActionScheduler_LogEntry[]
42 */
43 abstract public function get_logs( $action_id );
44
45
46 /**
47 * @codeCoverageIgnore
48 */
49 public function init() {
50 $this->hook_stored_action();
51 add_action( 'action_scheduler_canceled_action', array( $this, 'log_canceled_action' ), 10, 1 );
52 add_action( 'action_scheduler_begin_execute', array( $this, 'log_started_action' ), 10, 2 );
53 add_action( 'action_scheduler_after_execute', array( $this, 'log_completed_action' ), 10, 3 );
54 add_action( 'action_scheduler_failed_execution', array( $this, 'log_failed_action' ), 10, 3 );
55 add_action( 'action_scheduler_failed_action', array( $this, 'log_timed_out_action' ), 10, 2 );
56 add_action( 'action_scheduler_unexpected_shutdown', array( $this, 'log_unexpected_shutdown' ), 10, 2 );
57 add_action( 'action_scheduler_reset_action', array( $this, 'log_reset_action' ), 10, 1 );
58 add_action( 'action_scheduler_execution_ignored', array( $this, 'log_ignored_action' ), 10, 2 );
59 add_action( 'action_scheduler_failed_fetch_action', array( $this, 'log_failed_fetch_action' ), 10, 2 );
60 add_action( 'action_scheduler_failed_to_schedule_next_instance', array( $this, 'log_failed_schedule_next_instance' ), 10, 2 );
61 add_action( 'action_scheduler_bulk_cancel_actions', array( $this, 'bulk_log_cancel_actions' ), 10, 1 );
62 }
63
64 public function hook_stored_action() {
65 add_action( 'action_scheduler_stored_action', array( $this, 'log_stored_action' ) );
66 }
67
68 public function unhook_stored_action() {
69 remove_action( 'action_scheduler_stored_action', array( $this, 'log_stored_action' ) );
70 }
71
72 public function log_stored_action( $action_id ) {
73 $this->log( $action_id, __( 'action created', 'action-scheduler' ) );
74 }
75
76 public function log_canceled_action( $action_id ) {
77 $this->log( $action_id, __( 'action canceled', 'action-scheduler' ) );
78 }
79
80 public function log_started_action( $action_id, $context = '' ) {
81 if ( ! empty( $context ) ) {
82 /* translators: %s: context */
83 $message = sprintf( __( 'action started via %s', 'action-scheduler' ), $context );
84 } else {
85 $message = __( 'action started', 'action-scheduler' );
86 }
87 $this->log( $action_id, $message );
88 }
89
90 public function log_completed_action( $action_id, $action = null, $context = '' ) {
91 if ( ! empty( $context ) ) {
92 /* translators: %s: context */
93 $message = sprintf( __( 'action complete via %s', 'action-scheduler' ), $context );
94 } else {
95 $message = __( 'action complete', 'action-scheduler' );
96 }
97 $this->log( $action_id, $message );
98 }
99
100 public function log_failed_action( $action_id, Exception $exception, $context = '' ) {
101 if ( ! empty( $context ) ) {
102 /* translators: 1: context 2: exception message */
103 $message = sprintf( __( 'action failed via %1$s: %2$s', 'action-scheduler' ), $context, $exception->getMessage() );
104 } else {
105 /* translators: %s: exception message */
106 $message = sprintf( __( 'action failed: %s', 'action-scheduler' ), $exception->getMessage() );
107 }
108 $this->log( $action_id, $message );
109 }
110
111 public function log_timed_out_action( $action_id, $timeout ) {
112 /* translators: %s: amount of time */
113 $this->log( $action_id, sprintf( __( 'action marked as failed after %s seconds. Unknown error occurred. Check server, PHP and database error logs to diagnose cause.', 'action-scheduler' ), $timeout ) );
114 }
115
116 public function log_unexpected_shutdown( $action_id, $error ) {
117 if ( ! empty( $error ) ) {
118 /* translators: 1: error message 2: filename 3: line */
119 $this->log( $action_id, sprintf( __( 'unexpected shutdown: PHP Fatal error %1$s in %2$s on line %3$s', 'action-scheduler' ), $error['message'], $error['file'], $error['line'] ) );
120 }
121 }
122
123 public function log_reset_action( $action_id ) {
124 $this->log( $action_id, __( 'action reset', 'action-scheduler' ) );
125 }
126
127 public function log_ignored_action( $action_id, $context = '' ) {
128 if ( ! empty( $context ) ) {
129 /* translators: %s: context */
130 $message = sprintf( __( 'action ignored via %s', 'action-scheduler' ), $context );
131 } else {
132 $message = __( 'action ignored', 'action-scheduler' );
133 }
134 $this->log( $action_id, $message );
135 }
136
137 /**
138 * @param string $action_id
139 * @param Exception|NULL $exception The exception which occurred when fetching the action. NULL by default for backward compatibility.
140 *
141 * @return ActionScheduler_LogEntry[]
142 */
143 public function log_failed_fetch_action( $action_id, Exception $exception = null ) {
144
145 if ( ! is_null( $exception ) ) {
146 /* translators: %s: exception message */
147 $log_message = sprintf( __( 'There was a failure fetching this action: %s', 'action-scheduler' ), $exception->getMessage() );
148 } else {
149 $log_message = __( 'There was a failure fetching this action', 'action-scheduler' );
150 }
151
152 $this->log( $action_id, $log_message );
153 }
154
155 public function log_failed_schedule_next_instance( $action_id, Exception $exception ) {
156 /* translators: %s: exception message */
157 $this->log( $action_id, sprintf( __( 'There was a failure scheduling the next instance of this action: %s', 'action-scheduler' ), $exception->getMessage() ) );
158 }
159
160 /**
161 * Bulk add cancel action log entries.
162 *
163 * Implemented here for backward compatibility. Should be implemented in parent loggers
164 * for more performant bulk logging.
165 *
166 * @param array $action_ids List of action ID.
167 */
168 public function bulk_log_cancel_actions( $action_ids ) {
169 if ( empty( $action_ids ) ) {
170 return;
171 }
172
173 foreach ( $action_ids as $action_id ) {
174 $this->log_canceled_action( $action_id );
175 }
176 }
177 }
178