Add live log buffering support and endpoint; enhance log display functionality.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
use crate::fat_error::FatResult;
|
||||
use crate::log::LOG_ACCESS;
|
||||
use alloc::string::String;
|
||||
use alloc::vec::Vec;
|
||||
use edge_http::io::server::Connection;
|
||||
use edge_nal::io::{Read, Write};
|
||||
use serde::Serialize;
|
||||
|
||||
pub(crate) async fn get_log<T, const N: usize>(
|
||||
conn: &mut Connection<'_, T, N>,
|
||||
@@ -34,3 +37,29 @@ where
|
||||
conn.write_all("]".as_bytes()).await?;
|
||||
Ok(Some(200))
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct LiveLogEntry {
|
||||
seq: u64,
|
||||
text: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct LiveLogResponse {
|
||||
entries: Vec<LiveLogEntry>,
|
||||
dropped: bool,
|
||||
next_seq: u64,
|
||||
}
|
||||
|
||||
pub(crate) async fn get_live_log(after: Option<u64>) -> FatResult<Option<String>> {
|
||||
let (raw_entries, dropped, next_seq) = crate::log::INTERCEPTOR.get_live_logs(after);
|
||||
let response = LiveLogResponse {
|
||||
entries: raw_entries
|
||||
.into_iter()
|
||||
.map(|(seq, text)| LiveLogEntry { seq, text })
|
||||
.collect(),
|
||||
dropped,
|
||||
next_seq,
|
||||
};
|
||||
Ok(Some(serde_json::to_string(&response)?))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user