From 26a283e0a2c3a2b5bdb1b462f6fa5768adcd2605 Mon Sep 17 00:00:00 2001 From: puffycid Date: Sun, 10 May 2026 21:20:26 -0400 Subject: [PATCH] migrate to tracing crate --- Cargo.lock | 57 ++++++++++++++++++++++++++++++++++++-------- Cargo.toml | 4 ++-- src/lib.rs | 2 +- src/light.rs | 7 ++++-- src/tags/parser.rs | 11 +++++---- src/utils/strings.rs | 7 ++++-- 6 files changed, 67 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d386d33..aadf425 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10,15 +10,9 @@ checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "itoa" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" - -[[package]] -name = "log" -version = "0.4.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] name = "memchr" @@ -35,6 +29,18 @@ dependencies = [ "memchr", ] +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + [[package]] name = "proc-macro2" version = "1.0.106" @@ -98,13 +104,13 @@ dependencies = [ [[package]] name = "sunlight" -version = "0.1.5" +version = "0.2.0" dependencies = [ "base64", - "log", "nom", "serde", "serde_json", + "tracing", ] [[package]] @@ -118,6 +124,37 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + [[package]] name = "unicode-ident" version = "1.0.24" diff --git a/Cargo.toml b/Cargo.toml index afa9e2e..8725e74 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sunlight" -version = "0.1.5" +version = "0.2.0" edition = "2024" license = "MIT" repository = "https://github.com/puffyCid/sunlight" @@ -10,6 +10,6 @@ keywords = ["forensics"] [dependencies] nom = "8.0.0" serde = { version = "1.0.228", features = ["derive"] } -log = "0.4.29" +tracing = "0.1.44" serde_json = "1.0.149" base64 = "0.22.1" diff --git a/src/lib.rs b/src/lib.rs index f2ffcf4..4817dce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,7 @@ clippy::dbg_macro, clippy::debug_assert_with_mut_call, clippy::doc_markdown, - clippy::empty_enum, + clippy::empty_enums, clippy::enum_glob_use, clippy::exit, clippy::expl_impl_clone_on_copy, diff --git a/src/light.rs b/src/light.rs index 21c8212..3782bf4 100644 --- a/src/light.rs +++ b/src/light.rs @@ -1,8 +1,8 @@ use crate::{error::SunlightError, tags::parser::parse_tag}; -use log::error; use serde::Serialize; use serde_json::Value; use std::collections::HashMap; +use tracing::{Level, event}; #[derive(Debug, Serialize)] pub struct ProtoTag { @@ -76,7 +76,10 @@ pub fn extract_protobuf(data: &[u8]) -> Result, Sunligh let proto_map = match proto_result { Ok((_, results)) => results, Err(err) => { - error!("[sunlight] could not parse provided protobuf bytes: {err:?}"); + event!( + Level::ERROR, + "[sunlight] could not parse provided protobuf bytes: {err:?}" + ); return Err(SunlightError::Parser); } }; diff --git a/src/tags/parser.rs b/src/tags/parser.rs index ee1899e..8bb810d 100644 --- a/src/tags/parser.rs +++ b/src/tags/parser.rs @@ -7,9 +7,9 @@ use crate::{ }, utils::encoding::base64_encode_standard, }; -use log::warn; use serde_json::Value; use std::collections::HashMap; +use tracing::{Level, event}; /// Extract the Protobuf values from the provided data pub(crate) fn parse_tag(data: &[u8]) -> nom::IResult<&[u8], HashMap> { @@ -24,20 +24,23 @@ pub(crate) fn parse_tag(data: &[u8]) -> nom::IResult<&[u8], HashMap parse_fixed64(input)?, WireType::Len => parse_length_tag(input)?, WireType::StartGroup => { - warn!( + event!( + Level::WARN, "[sunlight] got start group wiretype. This is deprecated, ending parsing now. Returning base64 as final result" ); ([].as_slice(), Value::String(base64_encode_standard(input))) } WireType::EndGroup => { - warn!( + event!( + Level::WARN, "[sunlight] got end group wiretype. This is deprecated, ending parsing now. Returning base64 as final result" ); ([].as_slice(), Value::String(base64_encode_standard(input))) } WireType::Fixed32 => parse_fixed32(input)?, WireType::Unknown => { - warn!( + event!( + Level::WARN, "[sunlight] got unknown wire type. Protobuf data may be corrupted or this is not protobuf data, ending parsing now. Returning base64 as final result" ); ([].as_slice(), Value::String(base64_encode_standard(input))) diff --git a/src/utils/strings.rs b/src/utils/strings.rs index 46d8142..61f3ff8 100644 --- a/src/utils/strings.rs +++ b/src/utils/strings.rs @@ -1,5 +1,5 @@ use crate::utils::encoding::base64_encode_standard; -use log::warn; +use tracing::{Level, event}; /// Get a UTF8 string from provided bytes data. Invalid UTF8 is base64 encoded. Use `extract_uf8_string_lossy` if replacing bytes is acceptable pub(crate) fn extract_utf8_string(data: &[u8]) -> String { @@ -7,7 +7,10 @@ pub(crate) fn extract_utf8_string(data: &[u8]) -> String { match utf8_result { Ok(result) => result.trim_end_matches('\0').to_string(), Err(err) => { - warn!("Failed to get UTF8 string for Protobuf: {err:?}"); + event!( + Level::WARN, + "Failed to get UTF8 string for Protobuf: {err:?}" + ); let max_size = 2097152; let issue = if data.len() < max_size { base64_encode_standard(data)