Skip to content

Commit

Permalink
style: Improve log formatting consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
j5ik2o committed Jul 13, 2024
1 parent 0b16e96 commit f554a36
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 46 deletions.
10 changes: 4 additions & 6 deletions src/actor/context/actor_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1100,12 +1100,10 @@ impl Supervisor for ActorContext {
reason
);
P_LOG
.error(
&format!(
"[Supervision] Actor: {}, failed with message: {}, exception: {}",
self_pid, message_handle, reason
),
)
.error(&format!(
"[Supervision] Actor: {}, failed with message: {}, exception: {}",
self_pid, message_handle, reason
))
.await;
}

Expand Down
26 changes: 11 additions & 15 deletions src/actor/dispatch/dead_letter_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ impl DeadLetterProcess {
.clone();
let func = ThrottleCallback::new(move |i: usize| async move {
P_LOG
.info(
&format!("DeadLetterProcess: Throttling dead letters, count: {}", i),
)
.info(&format!("DeadLetterProcess: Throttling dead letters, count: {}", i))
.await;
});
let throttle = Throttle::new(dead_letter_throttle_count, dead_letter_throttle_interval, func).await;
Expand Down Expand Up @@ -85,18 +83,16 @@ impl DeadLetterProcess {
if let Some(is_ignore_dead_letter) = dead_letter.message_handle.to_typed::<IgnoreDeadLetterLogging>() {
if cloned_throttle.should_throttle() == Valve::Open {
P_LOG
.debug(
&format!(
"DeadLetterProcess: Message from {} to {} was not delivered, message: {:?}",
dead_letter.sender.as_ref().unwrap(),
dead_letter
.pid
.as_ref()
.map(|v| v.to_string())
.unwrap_or("None".to_string()),
is_ignore_dead_letter,
)
)
.debug(&format!(
"DeadLetterProcess: Message from {} to {} was not delivered, message: {:?}",
dead_letter.sender.as_ref().unwrap(),
dead_letter
.pid
.as_ref()
.map(|v| v.to_string())
.unwrap_or("None".to_string()),
is_ignore_dead_letter,
))
.await
}
}
Expand Down
9 changes: 2 additions & 7 deletions src/actor/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@ use once_cell::sync::Lazy;
use crate::log::log::Logger;
use crate::log::log_event_stream::get_global_log_event_stream;

pub static P_LOG: Lazy<Logger> = Lazy::new(|| {
Logger::new(
get_global_log_event_stream(),
crate::log::log::Level::Debug,
"[ACTOR]",
)
});
pub static P_LOG: Lazy<Logger> =
Lazy::new(|| Logger::new(get_global_log_event_stream(), crate::log::log::Level::Debug, "[ACTOR]"));

pub fn set_log_level(level: crate::log::log::Level) {
P_LOG.set_level(level);
Expand Down
24 changes: 6 additions & 18 deletions src/log/log_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@ mod tests {
#[tokio::test]
async fn test_off_level_only_context() {
let event_stream = LogEventStream::new();
let l = Logger::new(
event_stream,
Level::Min,
"").with_fields(
[LogField::int("bar", 32), LogField::bool("fum", false)],
);
let l =
Logger::new(event_stream, Level::Min, "").with_fields([LogField::int("bar", 32), LogField::bool("fum", false)]);
l.debug("foo").await;
}

Expand All @@ -44,12 +40,8 @@ mod tests {
let event_stream = LogEventStream::new();
let _s1 = subscribe_stream(&event_stream, |_: LogEvent| async {}).await;

let l = Logger::new(
event_stream,
Level::Debug,
"").with_fields(
[LogField::int("bar", 32), LogField::bool("fum", false)],
);
let l =
Logger::new(event_stream, Level::Debug, "").with_fields([LogField::int("bar", 32), LogField::bool("fum", false)]);
l.debug("foo").await;

unsubscribe_stream(&_s1).await;
Expand All @@ -61,12 +53,8 @@ mod tests {
let _s1 = subscribe_stream(&event_stream, |_: LogEvent| async {}).await;
let _s2 = subscribe_stream(&event_stream, |_: LogEvent| async {}).await;

let l = Logger::new(
event_stream,
Level::Debug,
"").with_fields(
[LogField::int("bar", 32), LogField::bool("fum", false)],
);
let l =
Logger::new(event_stream, Level::Debug, "").with_fields([LogField::int("bar", 32), LogField::bool("fum", false)]);
l.debug("foo").await;

unsubscribe_stream(&_s1).await;
Expand Down

0 comments on commit f554a36

Please sign in to comment.