get( $key_name, '' ); if ( '' !== $key ) { $message = str_replace( $key, '[redacted]', $message ); } } $message = preg_replace( '/([?&]key=)[^\s&]+/i', '$1[redacted]', $message ); $timestamp = current_time( 'Y-m-d H:i:s' ); $context_json = ''; // Do not record arbitrary provider payloads or user content. $formatted = sprintf( "[%s] [%s] %s%s\n", $timestamp, strtoupper( $level ), $message, $context_json ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log error_log( $formatted ); } /** * Log info. * * @param string $message Log message. * @param array $context Context data. * @return void */ public static function info( string $message, array $context = array() ): void { self::log( 'INFO', $message, $context ); } /** * Log error. * * @param string $message Log message. * @param array $context Context data. * @return void */ public static function error( string $message, array $context = array() ): void { self::log( 'ERROR', $message, $context ); } /** * Log warning. * * @param string $message Log message. * @param array $context Context data. * @return void */ public static function warning( string $message, array $context = array() ): void { self::log( 'WARNING', $message, $context ); } /** * Log debug. * * @param string $message Log message. * @param array $context Context data. * @return void */ public static function debug( string $message, array $context = array() ): void { if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { self::log( 'DEBUG', $message, $context ); } } }