systemprompt-logging 0.65.0

Tracing and audit infrastructure for systemprompt.io AI governance. Structured events, five-point audit traces, and SIEM-ready JSON output — part of the MCP governance pipeline.
Documentation
//! Logging error types.
//!
//! Copyright (c) systemprompt.io — Business Source License 1.1.
//! See <https://systemprompt.io> for licensing details.

#[derive(Debug, thiserror::Error)]
pub enum LoggingError {
    #[error("Invalid log entry: {field} {reason}")]
    InvalidLogEntry { field: String, reason: String },

    #[error("Log entry validation failed: {message}")]
    ValidationError { message: String },

    #[error("Invalid log level: {level}")]
    InvalidLogLevel { level: String },

    #[error("Log entry not found: {id}")]
    LogEntryNotFound { id: String },

    #[error("Empty log module name")]
    EmptyModuleName,

    #[error("Empty log message")]
    EmptyMessage,

    #[error("Invalid metadata format")]
    InvalidMetadata,

    #[error("Repository operation failed: {0}")]
    Repository(#[from] systemprompt_traits::RepositoryError),

    #[error("JSON serialization failed")]
    JsonError(#[from] serde_json::Error),

    #[error("UUID generation failed")]
    UuidError(#[from] uuid::Error),

    #[error("DateTime parsing failed")]
    DateTimeError(#[from] chrono::ParseError),

    #[error("Cleanup operation failed: deleted {count} entries")]
    CleanupError { count: u64 },

    #[error("Pagination parameters invalid: page={page}, per_page={per_page}")]
    PaginationError { page: i32, per_page: i32 },

    #[error("Log filter invalid: {filter_type}={value}")]
    FilterError { filter_type: String, value: String },

    #[error("Terminal output failed")]
    TerminalError,

    #[error("Database connection not available")]
    DatabaseUnavailable,

    #[error("No task found matching: {partial_id}")]
    TaskNotFound { partial_id: String },
}

impl LoggingError {
    pub fn invalid_log_entry(field: impl Into<String>, reason: impl Into<String>) -> Self {
        Self::InvalidLogEntry {
            field: field.into(),
            reason: reason.into(),
        }
    }

    pub fn validation_error(message: impl Into<String>) -> Self {
        Self::ValidationError {
            message: message.into(),
        }
    }

    pub fn invalid_log_level(level: impl Into<String>) -> Self {
        Self::InvalidLogLevel {
            level: level.into(),
        }
    }

    pub fn log_entry_not_found(id: impl Into<String>) -> Self {
        Self::LogEntryNotFound { id: id.into() }
    }

    pub const fn cleanup_error(count: u64) -> Self {
        Self::CleanupError { count }
    }

    pub const fn pagination_error(page: i32, per_page: i32) -> Self {
        Self::PaginationError { page, per_page }
    }

    pub fn filter_error(filter_type: impl Into<String>, value: impl Into<String>) -> Self {
        Self::FilterError {
            filter_type: filter_type.into(),
            value: value.into(),
        }
    }
}

impl From<sqlx::Error> for LoggingError {
    fn from(err: sqlx::Error) -> Self {
        Self::Repository(systemprompt_traits::RepositoryError::from(err))
    }
}