Spaces:
Running
Running
| --- | |
| title: logging | |
| sidebarTitle: logging | |
| --- | |
| # `fastmcp.server.middleware.logging` | |
| Comprehensive logging middleware for FastMCP servers. | |
| ## Classes | |
| ### `LoggingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/logging.py#L10" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | |
| Middleware that provides comprehensive request and response logging. | |
| Logs all MCP messages with configurable detail levels. Useful for debugging, | |
| monitoring, and understanding server usage patterns. | |
| **Methods:** | |
| #### `on_message` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/logging.py#L71" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | |
| ```python | |
| on_message(self, context: MiddlewareContext, call_next: CallNext) -> Any | |
| ``` | |
| Log all messages. | |
| ### `StructuredLoggingMiddleware` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/logging.py#L92" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | |
| Middleware that provides structured JSON logging for better log analysis. | |
| Outputs structured logs that are easier to parse and analyze with log | |
| aggregation tools like ELK stack, Splunk, or cloud logging services. | |
| **Methods:** | |
| #### `on_message` <sup><a href="https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/middleware/logging.py#L149" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup> | |
| ```python | |
| on_message(self, context: MiddlewareContext, call_next: CallNext) -> Any | |
| ``` | |
| Log structured message information. | |