From 20fbce0cf0a8b88f205d8275e0b388643dede052 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Mon, 23 Dec 2024 08:01:44 +0000 Subject: [PATCH] chore: log spawned actor details on single line --- src/macros/spawn.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/macros/spawn.rs b/src/macros/spawn.rs index a679a45..0a288fd 100644 --- a/src/macros/spawn.rs +++ b/src/macros/spawn.rs @@ -3,23 +3,41 @@ #[macro_export] macro_rules! spawn { ($parent:expr, $actor:expr) => {{ - tracing::debug!("spawning : {}", stringify!($actor)); + tracing::debug!("spawning : {}", $crate::stringify_expr!($actor)); let new_actor_ref = kameo::spawn($actor); new_actor_ref.link(&$parent).await; $parent.link(&new_actor_ref).await; - tracing::debug!("spawned : {}", stringify!($actor)); + tracing::debug!("spawned : {}", $crate::stringify_expr!($actor)); new_actor_ref }}; } +#[macro_export] +macro_rules! stringify_expr { + ($expr:expr) => { + stringify!($expr).lines().collect::>().join(" ") + }; +} + +#[test] +fn remove_line_breaks() { + let out = stringify_expr!([ + "line 1", "line 2", "line 3", "line 1", "line 2", "line 3", "line 1", "line 2", "line 3", + "line 1", "line 2", "line 3", + ]); + let expected = r#"["line 1", "line 2", "line 3", "line 1", "line 2", "line 3", "line 1", "line 2", "line 3", "line 1", "line 2", "line 3",]"#; + + assert_eq!(out, expected); +} + #[macro_export] macro_rules! spawn_in_thread { ($parent:expr, $actor:expr) => {{ - tracing::debug!("spawning in thread : {}", stringify!($actor)); + tracing::debug!("spawning in thread : {}", $crate::stringify_expr!($actor)); let new_actor_ref = kameo::actor::spawn_in_thread($actor); new_actor_ref.link(&$parent).await; $parent.link(&new_actor_ref).await; - tracing::debug!("spawned in thread : {}", stringify!($actor)); + tracing::debug!("spawned in thread : {}", $crate::stringify_expr!($actor)); new_actor_ref }}; }