User UI improvement begins
This commit is contained in:
parent
203da4d593
commit
d776789de2
@ -34,17 +34,21 @@ impl Logger {
|
||||
|
||||
pub async fn add_system_log<T: Into<String>, U: Into<String>, V: Into<String>>(level: LogLevel, position: T, message: U, debug_info: V) {
|
||||
let log_entry = LogEntry::new(level, position, message, debug_info);
|
||||
println!("{log_entry}");
|
||||
Self::logging_console(log_entry.clone());
|
||||
let mut logger = Self::instance_mut().await;
|
||||
logger.system_log.push_back(log_entry);
|
||||
}
|
||||
|
||||
pub async fn add_system_log_entry(log_entry: LogEntry) {
|
||||
Self::logging_console(log_entry.clone());
|
||||
let mut logger = Self::instance_mut().await;
|
||||
println!("{log_entry}");
|
||||
logger.system_log.push_back(log_entry);
|
||||
}
|
||||
|
||||
pub fn logging_console(log_entry: LogEntry) {
|
||||
println!("{}", log_entry.to_colored_string());
|
||||
}
|
||||
|
||||
pub async fn get_system_logs() -> VecDeque<LogEntry> {
|
||||
Self::instance().await.system_log.clone()
|
||||
}
|
||||
|
||||
@ -16,9 +16,22 @@ pub enum LogLevel {
|
||||
Emergency,
|
||||
}
|
||||
|
||||
impl Display for LogLevel {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let str = match self {
|
||||
impl LogLevel {
|
||||
pub fn to_plain_string(&self) -> String {
|
||||
match self {
|
||||
LogLevel::Debug => "Debug ".to_string(),
|
||||
LogLevel::Information => "Information".to_string(),
|
||||
LogLevel::Notice => "Notice ".to_string(),
|
||||
LogLevel::Warning => "Warning ".to_string(),
|
||||
LogLevel::Error => "Error ".to_string(),
|
||||
LogLevel::Critical => "Critical ".to_string(),
|
||||
LogLevel::Alert => "Alert ".to_string(),
|
||||
LogLevel::Emergency => "Emergency ".to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_colored_string(&self) -> ColoredString {
|
||||
match self {
|
||||
LogLevel::Debug => "Debug ".to_string().bright_black(),
|
||||
LogLevel::Information => "Information".to_string().bright_blue(),
|
||||
LogLevel::Notice => "Notice ".to_string().bright_green(),
|
||||
@ -27,7 +40,13 @@ impl Display for LogLevel {
|
||||
LogLevel::Critical => "Critical ".to_string().bright_yellow(),
|
||||
LogLevel::Alert => "Alert ".to_string().red(),
|
||||
LogLevel::Emergency => "Emergency ".to_string().magenta(),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for LogLevel {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let str = self.to_plain_string();
|
||||
write!(f, "{}", str)
|
||||
}
|
||||
}
|
||||
@ -53,9 +72,23 @@ impl LogEntry {
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for LogEntry {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let level = self.level.to_string();
|
||||
impl LogEntry {
|
||||
pub fn to_plain_string(&self) -> String {
|
||||
let level = self.level.to_plain_string();
|
||||
let timestramp = self.timestamp.format("%Y/%m/%d %H:%M:%S").to_string();
|
||||
let position = self.position.clone();
|
||||
let message = self.message.clone();
|
||||
let str = if self.debug_info.is_empty() {
|
||||
format!("[{}] {} {}: {}", level, timestramp, position, message)
|
||||
} else {
|
||||
let debug_info = self.debug_info.bright_black();
|
||||
format!("[{}] {} {}: {}\n{}", level, timestramp, position, message, debug_info)
|
||||
};
|
||||
str
|
||||
}
|
||||
|
||||
pub fn to_colored_string(&self) -> String {
|
||||
let level = self.level.to_colored_string();
|
||||
let timestramp = self.timestamp.format("%Y/%m/%d %H:%M:%S").to_string();
|
||||
let position = self.position.cyan();
|
||||
let message = self.message.white();
|
||||
@ -65,6 +98,13 @@ impl Display for LogEntry {
|
||||
let debug_info = self.debug_info.bright_black();
|
||||
format!("[{}] {} {}: {}\n{}", level, timestramp, position, message, debug_info)
|
||||
};
|
||||
str
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for LogEntry {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let str = self.to_plain_string();
|
||||
write!(f, "{}", str)
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,10 +10,6 @@ function formatDate(date) {
|
||||
return date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate()) + '-' + pad(date.getHours()) + '-' + pad(date.getMinutes()) + '-' + pad(date.getSeconds());
|
||||
}
|
||||
|
||||
function formatLogText(logText) {
|
||||
return logText.replace(/\n/g, '<br>');
|
||||
}
|
||||
|
||||
function loadSystemLog() {
|
||||
lastLogType = 'system';
|
||||
lastUpdate = new Date();
|
||||
@ -24,7 +20,7 @@ function loadSystemLog() {
|
||||
return response.text();
|
||||
})
|
||||
.then(data => {
|
||||
document.getElementById('log-container').innerHTML = formatLogText(data);
|
||||
document.getElementById('log-container').innerHTML = data;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Fetch error:', error);
|
||||
@ -47,7 +43,7 @@ function loadAgentLog() {
|
||||
return response.text();
|
||||
})
|
||||
.then(data => {
|
||||
document.getElementById('log-container').innerHTML = formatLogText(data);
|
||||
document.getElementById('log-container').innerHTML = data;
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Fetch error:', error);
|
||||
@ -70,7 +66,7 @@ function updateLog() {
|
||||
})
|
||||
.then(data => {
|
||||
if (data) {
|
||||
document.getElementById('log-container').innerHTML += formatLogText(data);
|
||||
document.getElementById('log-container').innerHTML += data;
|
||||
lastUpdate = new Date();
|
||||
}
|
||||
})
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
pub mod image_task;
|
||||
pub mod task;
|
||||
pub mod video_info;
|
||||
mod monitor;
|
||||
|
||||
pub use Common::management::utils::*;
|
||||
|
||||
8
ManagementLibrary/src/management/utils/monitor.rs
Normal file
8
ManagementLibrary/src/management/utils/monitor.rs
Normal file
@ -0,0 +1,8 @@
|
||||
struct Monitor {
|
||||
}
|
||||
|
||||
impl Monitor {
|
||||
pub fn new() -> Monitor {
|
||||
Monitor {}
|
||||
}
|
||||
}
|
||||
@ -71,7 +71,7 @@ impl Logger {
|
||||
}
|
||||
|
||||
pub fn logging_console(log_entry: LogEntry) {
|
||||
println!("{log_entry}");
|
||||
println!("{}", log_entry.to_colored_string());
|
||||
}
|
||||
|
||||
pub async fn get_system_logs() -> VecDeque<LogEntry> {
|
||||
@ -96,7 +96,7 @@ impl Logger {
|
||||
}
|
||||
|
||||
pub fn format_logs(logs: &VecDeque<LogEntry>) -> String {
|
||||
logs.iter().map(LogEntry::to_string).collect::<Vec<_>>().join("\n")
|
||||
logs.iter().map(LogEntry::to_plain_string).collect::<Vec<_>>().join("<br>")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user