1use chrono::{DateTime, Utc};
7use serde::{Deserialize, Serialize};
8
9pub const DEFAULT_LOGS_RETENTION_DAYS: i32 = 7;
11pub const DEFAULT_LOGS_MAX_ROWS: i32 = 100_000;
13#[cfg(feature = "server")]
15pub const MIN_LOGS_RETENTION_DAYS: i32 = 1;
16#[cfg(feature = "server")]
18pub const MAX_LOGS_RETENTION_DAYS: i32 = 90;
19#[cfg(feature = "server")]
21pub const MIN_LOGS_MAX_ROWS: i32 = 1_000;
22#[cfg(feature = "server")]
24pub const MAX_LOGS_MAX_ROWS: i32 = 1_000_000;
25
26#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
28pub struct LogEntry {
29 pub id: i64,
31 pub ts: DateTime<Utc>,
33 pub level: String,
35 pub target: String,
37 pub message: String,
39}
40
41#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
43pub struct LogsPage {
44 pub entries: Vec<LogEntry>,
46 pub next_cursor: Option<i64>,
48 pub dropped: u64,
50}
51
52#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
54pub struct LogSettings {
55 pub retention_days: i32,
57 pub max_rows: i32,
59}
60
61impl Default for LogSettings {
62 fn default() -> Self {
63 Self {
64 retention_days: DEFAULT_LOGS_RETENTION_DAYS,
65 max_rows: DEFAULT_LOGS_MAX_ROWS,
66 }
67 }
68}
69
70impl LogSettings {
71 #[cfg(feature = "server")]
73 pub fn clamp_retention(days: i32) -> i32 {
74 days.clamp(MIN_LOGS_RETENTION_DAYS, MAX_LOGS_RETENTION_DAYS)
75 }
76
77 #[cfg(feature = "server")]
79 pub fn clamp_max_rows(rows: i32) -> i32 {
80 rows.clamp(MIN_LOGS_MAX_ROWS, MAX_LOGS_MAX_ROWS)
81 }
82}