feat: add server-sent events for logging and activity tracking
- Implemented a custom tracing layer (`AppLogLayer`) to capture log events and broadcast them to SSE clients. - Created admin routes for streaming server logs and listing recent activity logs. - Added an activity log repository interface and SQLite implementation for persisting activity events. - Integrated activity logging into user authentication and channel CRUD operations. - Developed frontend components for displaying server logs and activity logs in the admin panel. - Enhanced the video player with a stats overlay for monitoring streaming metrics.
This commit is contained in:
@@ -8,11 +8,14 @@ use axum_extra::extract::cookie::Key;
|
||||
use infra::auth::jwt::{JwtConfig, JwtValidator};
|
||||
#[cfg(feature = "auth-oidc")]
|
||||
use infra::auth::oidc::OidcService;
|
||||
use std::sync::Arc;
|
||||
use std::collections::VecDeque;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tokio::sync::broadcast;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::events::EventBus;
|
||||
use domain::{ChannelService, ScheduleEngineService, UserService};
|
||||
use crate::log_layer::LogLine;
|
||||
use domain::{ActivityLogRepository, ChannelService, ScheduleEngineService, UserService};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
@@ -27,6 +30,12 @@ pub struct AppState {
|
||||
pub jwt_validator: Option<Arc<JwtValidator>>,
|
||||
pub config: Arc<Config>,
|
||||
pub event_tx: EventBus,
|
||||
/// Broadcast channel for streaming log lines to SSE clients.
|
||||
pub log_tx: broadcast::Sender<LogLine>,
|
||||
/// Ring buffer of recent log lines sent to new SSE clients on connect.
|
||||
pub log_history: Arc<Mutex<VecDeque<LogLine>>>,
|
||||
/// Repository for persisted in-app activity events.
|
||||
pub activity_log_repo: Arc<dyn ActivityLogRepository>,
|
||||
/// Index for the local-files provider, used by the rescan route.
|
||||
#[cfg(feature = "local-files")]
|
||||
pub local_index: Option<Arc<infra::LocalIndex>>,
|
||||
@@ -46,6 +55,9 @@ impl AppState {
|
||||
provider_registry: Arc<infra::ProviderRegistry>,
|
||||
config: Config,
|
||||
event_tx: EventBus,
|
||||
log_tx: broadcast::Sender<LogLine>,
|
||||
log_history: Arc<Mutex<VecDeque<LogLine>>>,
|
||||
activity_log_repo: Arc<dyn ActivityLogRepository>,
|
||||
) -> anyhow::Result<Self> {
|
||||
let cookie_key = Key::derive_from(config.cookie_secret.as_bytes());
|
||||
|
||||
@@ -118,6 +130,9 @@ impl AppState {
|
||||
jwt_validator,
|
||||
config: Arc::new(config),
|
||||
event_tx,
|
||||
log_tx,
|
||||
log_history,
|
||||
activity_log_repo,
|
||||
#[cfg(feature = "local-files")]
|
||||
local_index: None,
|
||||
#[cfg(feature = "local-files")]
|
||||
|
||||
Reference in New Issue
Block a user