| 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 |
|