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 #[cfg_attr(
33 target_arch = "wasm32",
34 serde(deserialize_with = "crate::models::rfc3339::deserialize")
35 )]
36 pub ts: DateTime<Utc>,
37 pub level: String,
39 pub target: String,
41 pub message: String,
43}
44
45#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
47pub struct LogsPage {
48 pub entries: Vec<LogEntry>,
50 pub next_cursor: Option<i64>,
52 pub dropped: u64,
54}
55
56#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
58pub struct LogSettings {
59 pub retention_days: i32,
61 pub max_rows: i32,
63}
64
65impl Default for LogSettings {
66 fn default() -> Self {
67 Self {
68 retention_days: DEFAULT_LOGS_RETENTION_DAYS,
69 max_rows: DEFAULT_LOGS_MAX_ROWS,
70 }
71 }
72}
73
74impl LogSettings {
75 #[cfg(feature = "server")]
77 pub fn clamp_retention(days: i32) -> i32 {
78 days.clamp(MIN_LOGS_RETENTION_DAYS, MAX_LOGS_RETENTION_DAYS)
79 }
80
81 #[cfg(feature = "server")]
83 pub fn clamp_max_rows(rows: i32) -> i32 {
84 rows.clamp(MIN_LOGS_MAX_ROWS, MAX_LOGS_MAX_ROWS)
85 }
86}