Skip to main content

systemprompt_logging/trace/models/
log.rs

1//! Log search and summary DTOs (level/module rollups, time ranges, pattern
2//! queries).
3//!
4//! Copyright (c) systemprompt.io — Business Source License 1.1.
5//! See <https://systemprompt.io> for licensing details.
6
7use chrono::{DateTime, Utc};
8use serde::{Deserialize, Serialize};
9use systemprompt_identifiers::{LogId, TraceId};
10
11#[derive(Debug, Clone)]
12pub struct LogSearchFilter {
13    pub pattern: String,
14    pub limit: i64,
15    pub since: Option<DateTime<Utc>>,
16    pub level: Option<String>,
17}
18
19impl LogSearchFilter {
20    pub const fn new(pattern: String, limit: i64) -> Self {
21        Self {
22            pattern,
23            limit,
24            since: None,
25            level: None,
26        }
27    }
28
29    pub const fn with_since(mut self, since: DateTime<Utc>) -> Self {
30        self.since = Some(since);
31        self
32    }
33
34    systemprompt_models::builder_methods! {
35        with_level(level) -> String,
36    }
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
40pub struct LogSearchItem {
41    pub id: LogId,
42    pub trace_id: TraceId,
43    pub timestamp: DateTime<Utc>,
44    pub level: String,
45    pub module: String,
46    pub message: String,
47    pub metadata: Option<String>,
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct LevelCount {
52    pub level: String,
53    pub count: i64,
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize)]
57pub struct ModuleCount {
58    pub module: String,
59    pub count: i64,
60}
61
62#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
63pub struct LogTimeRange {
64    pub earliest: Option<DateTime<Utc>>,
65    pub latest: Option<DateTime<Utc>>,
66}