diff --git a/Cargo.toml b/Cargo.toml index 2d8d707..dce1d91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ default = [] async = ["blocking", "futures"] panic_on_unsent_packets = [] verify_binary_signature = [] +enable_inner_logging = [] [dependencies] blocking = { version = "1", optional = true } diff --git a/src/log.rs b/src/log.rs index d86d7c6..832d6a6 100644 --- a/src/log.rs +++ b/src/log.rs @@ -21,11 +21,13 @@ pub(crate) struct LogItem { } impl LogItem { + #[allow(dead_code)] pub(crate) fn new(level: log::Level, msg: String, timestamp: u64) -> Self { Self { level, msg, timestamp } } } +#[cfg(feature = "enable_inner_logging")] static LOG_CONTAINER: std::sync::LazyLock>> = std::sync::LazyLock::new(|| std::sync::Mutex::new(std::collections::VecDeque::new())); @@ -35,13 +37,13 @@ static LOG_CONTAINER: std::sync::LazyLock { log::info!("WinTun: {}", utf8_msg); log::Level::Info @@ -54,13 +56,15 @@ pub unsafe extern "stdcall" fn default_logger( _ => log::Level::Error, }; + #[cfg(feature = "enable_inner_logging")] if let Err(e) = LOG_CONTAINER.lock().map(|mut log| { - log.push_back(LogItem::new(l, utf8_msg, timestamp)); + log.push_back(LogItem::new(_l, utf8_msg, _timestamp)); }) { log::error!("Failed to log message: {}", e); } } +#[cfg(feature = "enable_inner_logging")] fn get_log() -> Vec { LOG_CONTAINER .lock() @@ -68,6 +72,7 @@ fn get_log() -> Vec { .unwrap_or_else(|_e| Vec::new()) } +#[cfg(feature = "enable_inner_logging")] fn get_worst_log_msg(container: &[LogItem]) -> Option<&LogItem> { container.iter().max_by_key(|item| match item.level { log::Level::Error => 2, @@ -78,6 +83,9 @@ fn get_worst_log_msg(container: &[LogItem]) -> Option<&LogItem> { } pub(crate) fn extract_wintun_log_error(prifix: &str) -> Result { + #[cfg(not(feature = "enable_inner_logging"))] + let info = "".to_string(); + #[cfg(feature = "enable_inner_logging")] let info = get_worst_log_msg(&get_log()) .map(|item| item.msg.clone()) .unwrap_or_else(|| "No logs".to_string());