Skip to main content

systemprompt_logging/
extension.rs

1//! `Extension` registration for the logging subsystem: schema, priority,
2//! required flag.
3//!
4//! Copyright (c) systemprompt.io — Business Source License 1.1.
5//! See <https://systemprompt.io> for licensing details.
6
7use systemprompt_extension::prelude::*;
8
9#[derive(Debug, Clone, Copy, Default)]
10pub struct LoggingExtension;
11
12impl Extension for LoggingExtension {
13    fn metadata(&self) -> ExtensionMetadata {
14        ExtensionMetadata {
15            id: "logging",
16            name: "Logging",
17            version: env!("CARGO_PKG_VERSION"),
18        }
19    }
20
21    fn is_required(&self) -> bool {
22        true
23    }
24
25    fn schemas(&self) -> Vec<SchemaDefinition> {
26        vec![
27            SchemaDefinition::new("logs", include_str!("../schema/log.sql")).with_required_columns(
28                vec![
29                    "id".into(),
30                    "timestamp".into(),
31                    "level".into(),
32                    "module".into(),
33                    "message".into(),
34                ],
35            ),
36            SchemaDefinition::new("analytics_events", include_str!("../schema/analytics.sql"))
37                .with_required_columns(vec![
38                    "id".into(),
39                    "user_id".into(),
40                    "event_type".into(),
41                    "event_category".into(),
42                    "severity".into(),
43                    "timestamp".into(),
44                ]),
45        ]
46    }
47
48    fn migrations(&self) -> Vec<Migration> {
49        extension_migrations!()
50    }
51
52    fn dependencies(&self) -> Vec<&'static str> {
53        vec!["database", "users"]
54    }
55}
56
57register_extension!(LoggingExtension);