From b9222445eecd9a961bacb31eb572decc15356614 Mon Sep 17 00:00:00 2001 From: DJO <790521+Alenar@users.noreply.github.com> Date: Tue, 15 Oct 2024 17:04:38 +0200 Subject: [PATCH] fix(common): logger source for component that have generic where incorrect ie: for a `MithrilProverService::` the source name generated was `MKTreeStoreInMemory>` instead of `MithrilProverService`. --- mithril-common/src/logging.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/mithril-common/src/logging.rs b/mithril-common/src/logging.rs index 60fc5a7a08..fad33124a5 100644 --- a/mithril-common/src/logging.rs +++ b/mithril-common/src/logging.rs @@ -23,7 +23,14 @@ impl LoggerExtensions for Logger { fn component_name() -> &'static str { let complete_name = std::any::type_name::(); - complete_name.split("::").last().unwrap_or(complete_name) + let without_generic = { + if complete_name.contains('<') { + complete_name.split('<').next().unwrap_or("") + } else { + complete_name + } + }; + without_generic.split("::").last().unwrap_or(complete_name) } #[cfg(test)] @@ -38,6 +45,10 @@ mod tests { struct TestStructWithLifetime<'a>(&'a str); enum TestEnum {} + struct TestStructWithGeneric { + _phantom: std::marker::PhantomData, + } + mod test_mod { pub struct ScopedTestStruct; pub enum ScopedTestEnum {} @@ -66,6 +77,14 @@ mod tests { component_name::(), "TestStructWithLifetime" ); + assert_eq!( + component_name::>(), + "TestStructWithGeneric" + ); + assert_eq!( + component_name::>(), + "TestStructWithGeneric" + ); } #[test]