mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
Put logging time behind log_debug
This commit is contained in:
+2
-2
@@ -29,13 +29,13 @@ members = [
|
|||||||
default = []
|
default = []
|
||||||
|
|
||||||
log = []
|
log = []
|
||||||
log_debug = ["log"]
|
log_debug = ["log", "chrono"]
|
||||||
|
|
||||||
obfuscate_aes = ["ush-obfuscate/obfuscate_aes"]
|
obfuscate_aes = ["ush-obfuscate/obfuscate_aes"]
|
||||||
obfuscate_ref = ["ush-obfuscate/obfuscate_ref"]
|
obfuscate_ref = ["ush-obfuscate/obfuscate_ref"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
chrono = { workspace = true }
|
chrono = { workspace = true, optional = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
serde_json = { workspace = true }
|
serde_json = { workspace = true }
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,12 @@ macro_rules! log {
|
|||||||
#[cfg(not(feature = "log_debug"))]
|
#[cfg(not(feature = "log_debug"))]
|
||||||
None,
|
None,
|
||||||
|
|
||||||
std::time::SystemTime::now(),
|
#[cfg(feature = "log_debug")]
|
||||||
|
Some(std::time::SystemTime::now()),
|
||||||
|
#[cfg(not(feature = "log_debug"))]
|
||||||
|
None,
|
||||||
|
|
||||||
|
|
||||||
log_result
|
log_result
|
||||||
);
|
);
|
||||||
}};
|
}};
|
||||||
@@ -28,7 +33,11 @@ macro_rules! log {
|
|||||||
#[cfg(not(feature = "log_debug"))]
|
#[cfg(not(feature = "log_debug"))]
|
||||||
None,
|
None,
|
||||||
|
|
||||||
std::time::SystemTime::now(),
|
#[cfg(feature = "log_debug")]
|
||||||
|
Some(std::time::SystemTime::now()),
|
||||||
|
#[cfg(not(feature = "log_debug"))]
|
||||||
|
None,
|
||||||
|
|
||||||
log_result
|
log_result
|
||||||
);
|
);
|
||||||
}};
|
}};
|
||||||
|
|||||||
+2
-2
@@ -28,7 +28,7 @@ pub struct Record {
|
|||||||
log_level: LogLevel,
|
log_level: LogLevel,
|
||||||
location: Option<String>,
|
location: Option<String>,
|
||||||
// line: u32,
|
// line: u32,
|
||||||
time: SystemTime,
|
time: Option<SystemTime>,
|
||||||
message: String,
|
message: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ pub fn set_logger(logger: &'static dyn Logger) {
|
|||||||
pub fn add_record(
|
pub fn add_record(
|
||||||
log_level: LogLevel,
|
log_level: LogLevel,
|
||||||
location: Option<String>,
|
location: Option<String>,
|
||||||
time: SystemTime,
|
time: Option<SystemTime>,
|
||||||
message: String,
|
message: String,
|
||||||
) {
|
) {
|
||||||
logger().log(Record {
|
logger().log(Record {
|
||||||
|
|||||||
+17
-13
@@ -1,5 +1,3 @@
|
|||||||
use chrono::{DateTime, Utc};
|
|
||||||
|
|
||||||
use crate::logger::{LogLevel, Logger, Record};
|
use crate::logger::{LogLevel, Logger, Record};
|
||||||
|
|
||||||
pub struct PrettyLogger {
|
pub struct PrettyLogger {
|
||||||
@@ -35,19 +33,25 @@ pub fn log(message: &Record) {
|
|||||||
LogLevel::Error => format!("{ERROR_COLOR}ERR!"),
|
LogLevel::Error => format!("{ERROR_COLOR}ERR!"),
|
||||||
};
|
};
|
||||||
|
|
||||||
let date: DateTime<Utc> = message.time.into();
|
match (message.time, &message.location) {
|
||||||
let date = date.to_rfc2822().to_string();
|
(None, None) => {
|
||||||
|
println!("{} {WHITE}{}", log_level, message.message,);
|
||||||
|
}
|
||||||
|
|
||||||
let location = if let Some(ref location) = message.location {
|
#[cfg(feature = "log_debug")]
|
||||||
location
|
(Some(time), Some(location)) => {
|
||||||
} else {
|
use chrono::{DateTime, Utc};
|
||||||
&String::new()
|
|
||||||
};
|
|
||||||
|
|
||||||
println!(
|
let date: DateTime<Utc> = time.into();
|
||||||
"{OFF_WHITE}[{TIME_COLOR}{}{OFF_WHITE}] {} {WHITE}{} {GREY}{}{WHITE}",
|
|
||||||
date, log_level, message.message, location
|
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 {
|
impl PrettyLogger {
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#![macro_use]
|
#![macro_use]
|
||||||
extern crate unshell;
|
extern crate unshell;
|
||||||
|
|
||||||
use unshell::{info, logger::PrettyLogger, obfuscate::sym, tree::Tree};
|
use unshell::{info, logger::PrettyLogger, obfuscate::sym};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
PrettyLogger::init();
|
PrettyLogger::init();
|
||||||
|
|
||||||
let mut manager = Tree::new();
|
// let mut manager = Tree::new();
|
||||||
// manager.init_logger();
|
// manager.init_logger();
|
||||||
|
|
||||||
println!("{}", sym!("TEST"));
|
println!("{}", sym!("TEST"));
|
||||||
|
|||||||
Reference in New Issue
Block a user