mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-09 06:47:59 -06:00
Make debug logging into an optional feature
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#[cfg(feature = "log_debug")]
|
||||
#[macro_export]
|
||||
macro_rules! debug {
|
||||
($fmt:tt) => {{
|
||||
@@ -5,7 +6,12 @@ macro_rules! debug {
|
||||
|
||||
$crate::logger::add_record(
|
||||
$crate::logger::LogLevel::Debug,
|
||||
String::from(unshell_obfuscate::file_symbol!()),
|
||||
|
||||
#[cfg(feature = "log_debug")]
|
||||
Some(String::from(unshell_obfuscate::file_symbol!())),
|
||||
#[cfg(not(feature = "log_debug"))]
|
||||
None,
|
||||
|
||||
std::time::SystemTime::now(),
|
||||
log_result
|
||||
);
|
||||
@@ -15,13 +21,30 @@ macro_rules! debug {
|
||||
|
||||
$crate::logger::add_record(
|
||||
$crate::logger::LogLevel::Debug,
|
||||
String::from(unshell_obfuscate::file_symbol!()),
|
||||
|
||||
#[cfg(feature = "log_debug")]
|
||||
Some(String::from(unshell_obfuscate::file_symbol!())),
|
||||
#[cfg(not(feature = "log_debug"))]
|
||||
None,
|
||||
|
||||
std::time::SystemTime::now(),
|
||||
log_result
|
||||
);
|
||||
}};
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "log_debug"))]
|
||||
#[macro_export]
|
||||
macro_rules! debug {
|
||||
($fmt:tt) => {{
|
||||
let _ = $fmt;
|
||||
}};
|
||||
($fmt:tt, $($arg:expr),*) => {{
|
||||
let _ = $fmt;
|
||||
let _ = ($($arg),*);
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! info {
|
||||
($fmt:tt) => {{
|
||||
@@ -29,7 +52,12 @@ macro_rules! info {
|
||||
|
||||
$crate::logger::add_record(
|
||||
$crate::logger::LogLevel::Info,
|
||||
String::from(unshell_obfuscate::file_symbol!()),
|
||||
|
||||
#[cfg(feature = "log_debug")]
|
||||
Some(String::from(unshell_obfuscate::file_symbol!())),
|
||||
#[cfg(not(feature = "log_debug"))]
|
||||
None,
|
||||
|
||||
std::time::SystemTime::now(),
|
||||
log_result
|
||||
);
|
||||
@@ -39,7 +67,12 @@ macro_rules! info {
|
||||
|
||||
$crate::logger::add_record(
|
||||
$crate::logger::LogLevel::Info,
|
||||
String::from(unshell_obfuscate::file_symbol!()),
|
||||
|
||||
#[cfg(feature = "log_debug")]
|
||||
Some(String::from(unshell_obfuscate::file_symbol!())),
|
||||
#[cfg(not(feature = "log_debug"))]
|
||||
None,
|
||||
|
||||
std::time::SystemTime::now(),
|
||||
log_result
|
||||
);
|
||||
@@ -53,7 +86,12 @@ macro_rules! warn {
|
||||
|
||||
$crate::logger::add_record(
|
||||
$crate::logger::LogLevel::Warn,
|
||||
String::from(unshell_obfuscate::file_symbol!()),
|
||||
|
||||
#[cfg(feature = "log_debug")]
|
||||
Some(String::from(unshell_obfuscate::file_symbol!())),
|
||||
#[cfg(not(feature = "log_debug"))]
|
||||
None,
|
||||
|
||||
std::time::SystemTime::now(),
|
||||
log_result
|
||||
);
|
||||
@@ -63,7 +101,12 @@ macro_rules! warn {
|
||||
|
||||
$crate::logger::add_record(
|
||||
$crate::logger::LogLevel::Warn,
|
||||
String::from(unshell_obfuscate::file_symbol!()),
|
||||
|
||||
#[cfg(feature = "log_debug")]
|
||||
Some(String::from(unshell_obfuscate::file_symbol!())),
|
||||
#[cfg(not(feature = "log_debug"))]
|
||||
None,
|
||||
|
||||
std::time::SystemTime::now(),
|
||||
log_result
|
||||
);
|
||||
@@ -77,7 +120,12 @@ macro_rules! error {
|
||||
|
||||
$crate::logger::add_record(
|
||||
$crate::logger::LogLevel::Error,
|
||||
String::from(unshell_obfuscate::file_symbol!()),
|
||||
|
||||
#[cfg(feature = "log_debug")]
|
||||
Some(String::from(unshell_obfuscate::file_symbol!())),
|
||||
#[cfg(not(feature = "log_debug"))]
|
||||
None,
|
||||
|
||||
std::time::SystemTime::now(),
|
||||
log_result
|
||||
);
|
||||
@@ -87,7 +135,12 @@ macro_rules! error {
|
||||
|
||||
$crate::logger::add_record(
|
||||
$crate::logger::LogLevel::Error,
|
||||
String::from(unshell_obfuscate::file_symbol!()),
|
||||
|
||||
#[cfg(feature = "log_debug")]
|
||||
Some(String::from(unshell_obfuscate::file_symbol!())),
|
||||
#[cfg(not(feature = "log_debug"))]
|
||||
None,
|
||||
|
||||
std::time::SystemTime::now(),
|
||||
log_result
|
||||
);
|
||||
|
||||
@@ -18,7 +18,7 @@ pub enum LogLevel {
|
||||
#[derive(Debug)]
|
||||
pub struct Record {
|
||||
log_level: LogLevel,
|
||||
location: String,
|
||||
location: Option<String>,
|
||||
// line: u32,
|
||||
time: SystemTime,
|
||||
message: String,
|
||||
@@ -46,7 +46,12 @@ pub fn set_logger(logger: &'static dyn Logger) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_record(log_level: LogLevel, location: String, time: SystemTime, message: String) {
|
||||
pub fn add_record(
|
||||
log_level: LogLevel,
|
||||
location: Option<String>,
|
||||
time: SystemTime,
|
||||
message: String,
|
||||
) {
|
||||
logger().log(Record {
|
||||
log_level,
|
||||
location,
|
||||
|
||||
@@ -27,9 +27,11 @@ impl Logger for PrettyLogger {
|
||||
let date: DateTime<Utc> = message.time.into();
|
||||
let date = date.to_rfc2822().to_string();
|
||||
|
||||
let location = message.location.unwrap_or("".to_string());
|
||||
|
||||
println!(
|
||||
"{OFF_WHITE}[{TIME_COLOR}{}{OFF_WHITE}] {} {WHITE}{} {GREY}{}{WHITE}",
|
||||
date, log_level, message.message, message.location
|
||||
date, log_level, message.message, location
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user