PluginProbe
404 Solution / trunk
404 Solution vtrunk
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / feedback / FeedbackTransportLog.php

FeedbackTransportLog.php in 404 Solution trunk, at includes/feedback/FeedbackTransportLog.php

53 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) {
4 exit;
5 }
6
7 /**
8 * Shared logging shim for the FeedbackTransport family of classes. Lives in
9 * its own file so collaborators (FeedbackHttpClient, FeedbackPayloadSchemaGuard)
10 * can emit warnings without depending on FeedbackTransport itself, which would
11 * create a class-level dependency cycle (FeedbackTransport already depends on
12 * all of them).
13 *
14 * Routes through the plugin's Logging service when the service container is
15 * up, falls back to the centralized PHP error-log sink so messages aren't
16 * lost in standalone tests or early-boot contexts.
17 */
18 class ABJ_404_Solution_FeedbackTransportLog {
19
20 /**
21 * @param string $level 'info' | 'warn' | 'error'
22 * @param string $message
23 * @return void
24 */
25 public static function log(string $level, string $message): void {
26 if (function_exists('abj_service_optional')) {
27 try {
28 $logger = abj_service_optional('logging');
29 if (is_object($logger)) {
30 if ($level === 'info' && method_exists($logger, 'infoMessage')) {
31 $logger->infoMessage($message);
32 return;
33 }
34 if ($level === 'warn' && method_exists($logger, 'warn')) {
35 $logger->warn($message);
36 return;
37 }
38 if ($level === 'error' && method_exists($logger, 'errorMessage')) {
39 $logger->errorMessage($message);
40 return;
41 }
42 }
43 } catch (\Throwable $e) {
44 abj404_logPhpFallback(
45 'transport-fallback',
46 'FeedbackTransport logger lookup failed (' . $e->getMessage() . '); falling back to PHP error log'
47 );
48 }
49 }
50 abj404_logPhpFallback('transport-fallback', $message);
51 }
52 }
53