| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) { |
| 4 |
exit; |
| 5 |
} |
| 6 |
|
| 7 |
if (!function_exists('abj404_logPhpFallback')) { |
| 8 |
/** |
| 9 |
* Emit a last-resort PHP error-log breadcrumb when plugin logging is |
| 10 |
* unavailable or unsafe to call. |
| 11 |
* |
| 12 |
* This is the only production sink for raw error_log(). Normal code should |
| 13 |
* attempt the plugin logger first, then call this helper only for the final |
| 14 |
* PHP-log fallback path. |
| 15 |
* |
| 16 |
* @param string $category One of the audit categories for fallback logging. |
| 17 |
* @param string $message Human-readable diagnostic context. |
| 18 |
* @return void |
| 19 |
*/ |
| 20 |
function abj404_logPhpFallback(string $category, string $message): void { |
| 21 |
$allowedCategories = array( |
| 22 |
'early-boot', |
| 23 |
'logger-internal', |
| 24 |
'service-resolution-fallback', |
| 25 |
'fatal-handler-fallback', |
| 26 |
'transport-fallback', |
| 27 |
); |
| 28 |
|
| 29 |
$normalizedCategory = in_array($category, $allowedCategories, true) |
| 30 |
? $category |
| 31 |
: 'uncategorized:' . $category; |
| 32 |
$normalizedMessage = str_replace(array("\r", "\n"), ' ', $message); |
| 33 |
|
| 34 |
// @abj404-raw-error-log-allowed: logger-internal centralized PHP error-log fallback is the single approved raw sink when plugin logging is unavailable. |
| 35 |
@error_log('404 Solution: ' . $normalizedMessage . ' [' . $normalizedCategory . ']'); |
| 36 |
} |
| 37 |
} |
| 38 |
|