diff options
| author | Mason Reed <mason@vector35.com> | 2025-12-17 21:23:46 -0500 |
|---|---|---|
| committer | Mason Reed <35282038+emesare@users.noreply.github.com> | 2026-01-11 10:36:01 -0800 |
| commit | 168a3fd34824adc9c6a606cd144219701f15cccf (patch) | |
| tree | 9bbac31ece5ea6ab6627998d995a77f7f7e2f8e6 /plugins/warp/src/container | |
| parent | ca91bc1933976c62d24248f0f7c35af38451ff11 (diff) | |
[Rust] Replace `log` with `tracing`
- Added more documentation
- Replaced global named logger for plugins, fixing the issue when the CU has multiple (e.g. statically linked demo)
- Simplified some misc code
This is a breaking change, but I believe there is no better time to make it, we cannot continue to use the `log` crate, it is too limited for our needs.
Diffstat (limited to 'plugins/warp/src/container')
| -rw-r--r-- | plugins/warp/src/container/disk.rs | 3 | ||||
| -rw-r--r-- | plugins/warp/src/container/network.rs | 15 | ||||
| -rw-r--r-- | plugins/warp/src/container/network/client.rs | 11 |
3 files changed, 16 insertions, 13 deletions
diff --git a/plugins/warp/src/container/disk.rs b/plugins/warp/src/container/disk.rs index a0400f9d..5e4a5613 100644 --- a/plugins/warp/src/container/disk.rs +++ b/plugins/warp/src/container/disk.rs @@ -1,6 +1,7 @@ use crate::container::{ Container, ContainerError, ContainerResult, SourceId, SourcePath, SourceTag, }; +use binaryninja::tracing; use std::collections::{HashMap, HashSet}; use std::fmt::{Debug, Display, Formatter}; use std::hash::{Hash, Hasher}; @@ -42,7 +43,7 @@ impl DiskContainer { match (DiskContainerSource::new_from_path(path.clone()), path_ext) { (Ok(source), _) => Some((source_id, source)), (Err(err), Some("warp")) => { - log::error!("Failed to load source '{}' from disk: {}", path, err); + tracing::error!("Failed to load source '{}' from disk: {}", path, err); None } // We don't care to show errors loading for non-warp files. diff --git a/plugins/warp/src/container/network.rs b/plugins/warp/src/container/network.rs index d0ccd3ea..0908b103 100644 --- a/plugins/warp/src/container/network.rs +++ b/plugins/warp/src/container/network.rs @@ -3,6 +3,7 @@ use crate::container::{ Container, ContainerError, ContainerResult, ContainerSearchQuery, ContainerSearchResponse, SourceId, SourcePath, SourceTag, }; +use binaryninja::tracing; use directories::ProjectDirs; use std::collections::{HashMap, HashSet}; use std::fmt::{Debug, Display, Formatter}; @@ -102,7 +103,7 @@ impl NetworkContainer { guids: &[FunctionGUID], ) -> HashMap<SourceId, Vec<FunctionGUID>> { let Some(target_id) = target.and_then(|t| self.get_target_id(t)) else { - log::debug!("Cannot query functions source without a target, skipping..."); + tracing::debug!("Cannot query functions source without a target, skipping..."); return HashMap::new(); }; @@ -122,7 +123,7 @@ impl NetworkContainer { { Ok(queried_results) => queried_results, Err(e) => { - log::error!("Failed to query functions source: {}", e); + tracing::error!("Failed to query functions source: {}", e); return result; } }; @@ -170,12 +171,12 @@ impl NetworkContainer { { Ok(file) => file, Err(e) => { - log::error!("Failed to query functions: {}", e); + tracing::error!("Failed to query functions: {}", e); return; } }; - log::debug!("Got {} chunks from server", file.chunks.len()); + tracing::debug!("Got {} chunks from server", file.chunks.len()); for chunk in &file.chunks { match &chunk.kind { ChunkKind::Signature(sc) => { @@ -183,12 +184,12 @@ impl NetworkContainer { // Probe the source before attempting to access it, as it might not exist locally. self.probe_source(*source); match self.cache.add_functions(target, source, &functions) { - Ok(_) => log::debug!( + Ok(_) => tracing::debug!( "Added {} functions into cached source '{}'", functions.len(), source ), - Err(err) => log::error!( + Err(err) => tracing::error!( "Failed to add {} function into cached source '{}': {}", functions.len(), source, @@ -227,7 +228,7 @@ impl NetworkContainer { let _ = self.cache.insert_source(source_id, SourcePath(source_path)); } Err(e) => { - log::error!("Failed to probe source '{}': {}", source_id, e); + tracing::error!("Failed to probe source '{}': {}", source_id, e); } } } diff --git a/plugins/warp/src/container/network/client.rs b/plugins/warp/src/container/network/client.rs index 9f68180b..d3c94d1a 100644 --- a/plugins/warp/src/container/network/client.rs +++ b/plugins/warp/src/container/network/client.rs @@ -5,6 +5,7 @@ use crate::container::{ }; use base64::Engine; use binaryninja::download::DownloadProvider; +use binaryninja::tracing; use serde::Deserialize; use serde_json::json; use std::collections::HashMap; @@ -496,14 +497,14 @@ impl NetworkClient { let kind = match item.kind.as_str() { "function" => { let Some(data) = &item.data else { - log::warn!( + tracing::warn!( "Function item {} has no data from network, skipping...", item.id ); continue; }; let Some(func) = Function::from_bytes(&data) else { - log::warn!( + tracing::warn!( "Function item {} has invalid data from network, skipping...", item.id ); @@ -514,7 +515,7 @@ impl NetworkClient { "source" => ContainerSearchItemKind::Source { path: match item.name { None => { - log::warn!("Source item {} has no name", item.id); + tracing::warn!("Source item {} has no name", item.id); continue; } Some(name) => SourcePath(format!("{}/{}", self.server_url, name).into()), @@ -523,14 +524,14 @@ impl NetworkClient { }, "type" => { let Some(data) = &item.data else { - log::warn!( + tracing::warn!( "Type item {} has no data from network, skipping...", item.id ); continue; }; let Some(ty) = Type::from_bytes(&data) else { - log::warn!( + tracing::warn!( "Type item {} has invalid data from network, skipping...", item.id ); |
