Documentation
¶
Overview ¶
Package logging provides utility and helper functions and structs related to logging activity for both internal logs (regarding the centian proxy) and MCP requests/respoonses.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrLogsDirNotFound = errors.New("centian logs directory not found")
ErrLogsDirNotFound is returned when the Centian logs directory is missing.
var ErrNoLogEntries = errors.New("no log entries found")
ErrNoLogEntries is returned when log files exist but contain no valid entries.
Functions ¶
func FormatDisplayLine ¶
func FormatDisplayLine(entry *AnnotatedLogEntry) string
FormatDisplayLine converts an AnnotatedLogEntry into a human-readable summary string.
func GetLogsDirectory ¶
GetLogsDirectory returns the directory where Centian stores log files. Tests can override this path by setting the CENTIAN_LOG_DIR environment variable.
Types ¶
type AnnotatedLogEntry ¶
type AnnotatedLogEntry struct {
Event common.McpEventInterface
SourceFile string
}
AnnotatedLogEntry wraps a generic MCP event with contextual metadata used for display.
func LoadRecentLogEntries ¶
func LoadRecentLogEntries(limit int) ([]AnnotatedLogEntry, error)
LoadRecentLogEntries collects log entries from Centian log files, orders them by timestamp descending, and enforces an optional limit. A non-positive limit returns all available entries.
type BaseLogEntry ¶
type BaseLogEntry struct {
// Timestamp is the exact time when the log entry was created.
Timestamp time.Time `json:"timestamp"`
// RequestID uniquely identifies a single request/response pair.
RequestID string `json:"request_id"`
// SessionID groups multiple requests within the same proxy session.
SessionID string `json:"session_id,omitempty"`
// Direction indicates the communication flow perspective:.
// "request" (client→server),
// "response" (server→client), or.
// "system" (proxy lifecycle events).
// This field remains stable regardless of success/failure status.
Direction McpEventDirection `json:"direction"`
// ServerID uniquely identifies the MCP server instance handling this request.
ServerID string `json:"server_id,omitempty"`
// RawMessage container the raw input received for the specific message.
RawMessage string `json:"raw_message"`
// MessageType categorizes the content/outcome: "request", "response", "error", or "system".
// Unlike Direction, this changes to "error" for failed responses, enabling filtering.
// by operational status (e.g., "all errors" vs "all responses regardless of success").
// This orthogonal design supports both flow analysis (Direction) and status monitoring (MessageType).
MessageType McpMessageType `json:"message_type"`
// Success indicates whether the operation completed successfully.
Success bool `json:"success"`
// Error contains error details if Success is false.
Error string `json:"error,omitempty"`
// Metadata holds additional context-specific key-value pairs.
Metadata map[string]string `json:"metadata,omitempty"`
// Transport identifies the proxy type: "stdio", "http", "websocket".
Transport string `json:"transport"`
}
BaseLogEntry represents the basic fields for any log entry and is always included in all logs.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger handles log file I/O operations (base logger for all transports).
func (*Logger) GetLogPath ¶
GetLogPath returns the absolute path to the current log file. This method can be used by external callers to:.
- Display log location to users for debugging.
- Access logs programmatically for analysis or monitoring.
- Integrate with external log aggregation tools.
- Provide log file paths in status/diagnostic outputs.
func (*Logger) LogMcpEvent ¶
func (l *Logger) LogMcpEvent(event common.McpEventInterface) error
LogMcpEvent logs the provided stdio/http MCP event.
type McpEventDirection ¶
type McpEventDirection string
McpEventDirection identifies the direction of the MCP event, e.g. from client to server, or from proxy to client, etc.
const ( // DirectionClientToServer represents the direction from CLIENT to SERVER. DirectionClientToServer McpEventDirection = "[CLIENT -> SERVER]" // DirectionServerToClient represents the direction from SERVER to CLIENT. DirectionServerToClient McpEventDirection = "[SERVER -> CLIENT]" // DirectionCentianToClient represents the direction from CENTIAN to CLIENT, // e.g. when the event is returned prematurely back to the CLIENT due to processing. DirectionCentianToClient McpEventDirection = "[CENTIAN -> CLIENT]" // DirectionSystem represents that this is a SYSTEM event. // - meaning it is not forwarded to either CLIENT or SERVER. DirectionSystem McpEventDirection = "[SYSTEM]" // DirectionUnknown represents an unknown direction, // in case the direction is not one of the above! DirectionUnknown McpEventDirection = "[UNKNOWN]" )
func (McpEventDirection) MarshalJSON ¶
func (m McpEventDirection) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding for McpEventDirection. - if m does match any of the allowed values it is replaced with DirectionUnknown.
func (*McpEventDirection) UnmarshalJSON ¶
func (m *McpEventDirection) UnmarshalJSON(b []byte) error
UnmarshalJSON parses the JSON-encoded data of McpEventDirection. - if m does match any of the allowed values it is replaced with DirectionUnknown.
type McpMessageType ¶
type McpMessageType string
McpMessageType identifies the type of a MCP message, e.g. request, response, system, etc.
const ( // MessageTypeRequest identifies a message of type "request". MessageTypeRequest McpMessageType = "request" // MessageTypeResponse identifies a message of type "response". MessageTypeResponse McpMessageType = "response" // MessageTypeSystem identifies a message of type "system". MessageTypeSystem McpMessageType = "system" // MessageTypeUnknown identifies a message of type "unknown". MessageTypeUnknown McpMessageType = "unknown" // fallback in case of error )
func (McpMessageType) MarshalJSON ¶
func (m McpMessageType) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON encoding for McpMessageType. - if m does match any of the allowed values it is replaced with MessageTypeUnknown.
func (*McpMessageType) UnmarshalJSON ¶
func (m *McpMessageType) UnmarshalJSON(b []byte) error
UnmarshalJSON parses the JSON-encoded data of m. - if m does match any of the allowed values it is replaced with MessageTypeUnknown.