mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-09 06:47:59 -06:00
Put logging time behind log_debug
This commit is contained in:
@@ -12,7 +12,12 @@ macro_rules! log {
|
||||
#[cfg(not(feature = "log_debug"))]
|
||||
None,
|
||||
|
||||
std::time::SystemTime::now(),
|
||||
#[cfg(feature = "log_debug")]
|
||||
Some(std::time::SystemTime::now()),
|
||||
#[cfg(not(feature = "log_debug"))]
|
||||
None,
|
||||
|
||||
|
||||
log_result
|
||||
);
|
||||
}};
|
||||
@@ -28,7 +33,11 @@ macro_rules! log {
|
||||
#[cfg(not(feature = "log_debug"))]
|
||||
None,
|
||||
|
||||
std::time::SystemTime::now(),
|
||||
#[cfg(feature = "log_debug")]
|
||||
Some(std::time::SystemTime::now()),
|
||||
#[cfg(not(feature = "log_debug"))]
|
||||
None,
|
||||
|
||||
log_result
|
||||
);
|
||||
}};
|
||||
|
||||
+2
-2
@@ -28,7 +28,7 @@ pub struct Record {
|
||||
log_level: LogLevel,
|
||||
location: Option<String>,
|
||||
// line: u32,
|
||||
time: SystemTime,
|
||||
time: Option<SystemTime>,
|
||||
message: String,
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ pub fn set_logger(logger: &'static dyn Logger) {
|
||||
pub fn add_record(
|
||||
log_level: LogLevel,
|
||||
location: Option<String>,
|
||||
time: SystemTime,
|
||||
time: Option<SystemTime>,
|
||||
message: String,
|
||||
) {
|
||||
logger().log(Record {
|
||||
|
||||
+17
-13
@@ -1,5 +1,3 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
|
||||
use crate::logger::{LogLevel, Logger, Record};
|
||||
|
||||
pub struct PrettyLogger {
|
||||
@@ -35,19 +33,25 @@ pub fn log(message: &Record) {
|
||||
LogLevel::Error => format!("{ERROR_COLOR}ERR!"),
|
||||
};
|
||||
|
||||
let date: DateTime<Utc> = message.time.into();
|
||||
let date = date.to_rfc2822().to_string();
|
||||
match (message.time, &message.location) {
|
||||
(None, None) => {
|
||||
println!("{} {WHITE}{}", log_level, message.message,);
|
||||
}
|
||||
|
||||
let location = if let Some(ref location) = message.location {
|
||||
location
|
||||
} else {
|
||||
&String::new()
|
||||
};
|
||||
#[cfg(feature = "log_debug")]
|
||||
(Some(time), Some(location)) => {
|
||||
use chrono::{DateTime, Utc};
|
||||
|
||||
println!(
|
||||
"{OFF_WHITE}[{TIME_COLOR}{}{OFF_WHITE}] {} {WHITE}{} {GREY}{}{WHITE}",
|
||||
date, log_level, message.message, location
|
||||
);
|
||||
let date: DateTime<Utc> = time.into();
|
||||
|
||||
println!(
|
||||
"{OFF_WHITE}[{TIME_COLOR}{}{OFF_WHITE}] {} {WHITE}{} {GREY}{}{WHITE}",
|
||||
date, log_level, message.message, location
|
||||
);
|
||||
}
|
||||
|
||||
_ => unreachable!("All debug fields must be present or removed."),
|
||||
}
|
||||
}
|
||||
|
||||
impl PrettyLogger {
|
||||
|
||||
Reference in New Issue
Block a user