$context Safe metadata only (action keys, HTTP codes, counts). */ function adflipr_debug_log($message, array $context = []) { if (! adflipr_debug_logging_enabled()) { return; } $line = '[AdFlipr] ' . (string) $message; if (count($context) > 0) { $line .= ' ' . wp_json_encode(adflipr_debug_redact_context($context)); } // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- gated by ADFLIPR_DEBUG; no PII in $line. error_log($line); foreach (adflipr_debug_mirror_log_files() as $log_file) { if ($log_file === '') { continue; } // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- intentional mirror for local diagnostics. @error_log($line . "\n", 3, $log_file); } } /** * @param array $context * @return array */ function adflipr_debug_redact_context(array $context) { $redact_keys = array( 'Authorization', 'authorization', 'token', 'password', 'secret', 'consumer_key', 'consumer_secret', ); foreach ($redact_keys as $key) { if (array_key_exists($key, $context)) { $context[$key] = '[redacted]'; } } return $context; }