PluginProbe
ZIP AI – AI Website Builder & AI Agent (Beta) / 0.0.8
ZIP AI – AI Website Builder & AI Agent (Beta) v0.0.8
0.0.10 0.0.9 trunk 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8
zip-ai / lib / mcp-adapter / includes / Infrastructure / ErrorHandling / ErrorLogMcpErrorHandler.php

ErrorLogMcpErrorHandler.php in ZIP AI – AI Website Builder & AI Agent (Beta) 0.0.8, at lib/mcp-adapter/includes/Infrastructure/ErrorHandling/ErrorLogMcpErrorHandler.php

42 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ErrorLogMcpErrorHandler class for logging MCP errors to PHP error log.
4 *
5 * @package McpAdapter
6 */
7
8 declare( strict_types=1 );
9
10 namespace WP\MCP\Infrastructure\ErrorHandling;
11
12 /**
13 * Class ErrorLogMcpErrorHandler
14 *
15 * This class handles error logging by writing logs to the PHP error log.
16 *
17 * @package WP\MCP\ErrorHandlers
18 */
19 class ErrorLogMcpErrorHandler implements Contracts\McpErrorHandlerInterface {
20
21 /**
22 * Log with context.
23 *
24 * @param string $message The log message.
25 * @param array $context Additional context data.
26 * @param string $type The type of log (e.g., 'error', 'info', etc.). Default is 'error'.
27 *
28 * @return void
29 */
30 public function log( string $message, array $context = array(), string $type = 'error' ): void {
31 $user_id = function_exists( 'get_current_user_id' ) ? get_current_user_id() : 0;
32 $log_message = sprintf(
33 '[%s] %s | Context: %s | User ID: %d',
34 strtoupper( $type ),
35 $message,
36 wp_json_encode( $context ),
37 $user_id
38 );
39 error_log( $log_message ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
40 }
41 }
42