| @@ -117,9 +117,20 @@ | ||
| 117 | 117 | if ( '' !== $context_string ) { |
| 118 | 118 | $full_message .= ' | Context: ' . $context_string; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - self::write_log( $full_message ); | |
| 121 | + $written = self::write_log( $full_message ); | |
| 122 | + | |
| 123 | + // Forward after dedup so "repeated N times" remains one event, and only | |
| 124 | + // when the write itself was allowed: `woocommerce_pos_logging` is how a | |
| 125 | + // site says "do not record this", so it must gate the remote copy too. | |
| 126 | + if ( $written && ( 'error' === self::$log_level || 'critical' === self::$log_level ) ) { | |
| 127 | + try { | |
| 128 | + \WCPOS\WooCommercePOS\Services\Error_Reporter::report_log_error( self::$log_level, $message, $context_string ); | |
| 129 | + } catch ( \Throwable $t ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement.DetectedCatch | |
| 130 | + // Reporting must never break logging. | |
| 131 | + } | |
| 132 | + } | |
| 122 | 133 | } |
| 123 | 134 | |
| 124 | 135 | /** |
| 125 | 136 | * Flush any pending repeat count to the log. |
| @@ -185,12 +196,15 @@ | ||
| 185 | 196 | * Registers a shutdown hook on first write to flush any remaining |
| 186 | 197 | * repeat count at end of request. |
| 187 | 198 | * |
| 188 | 199 | * @param string $message The formatted message to write. |
| 200 | + * | |
| 201 | + * @return bool Whether the message was written, so callers can mirror the | |
| 202 | + * `woocommerce_pos_logging` decision instead of re-applying it. | |
| 189 | 203 | */ |
| 190 | - private static function write_log( string $message ): void { | |
| 204 | + private static function write_log( string $message ): bool { | |
| 191 | 205 | if ( ! apply_filters( 'woocommerce_pos_logging', true, $message ) ) { |
| 192 | - return; | |
| 206 | + return false; | |
| 193 | 207 | } |
| 194 | 208 | |
| 195 | 209 | if ( ! isset( self::$logger ) ) { |
| 196 | 210 | self::$logger = wc_get_logger(); |
| @@ -206,6 +220,8 @@ | ||
| 206 | 220 | Logger::flush_repeat_count(); |
| 207 | 221 | } |
| 208 | 222 | ); |
| 209 | 223 | } |
| 224 | + | |
| 225 | + return true; | |
| 210 | 226 | } |
| 211 | 227 | } |