Skip to content

Commit

Permalink
style: Remove redundant vec in log functions
Browse files Browse the repository at this point in the history
  • Loading branch information
j5ik2o committed Jul 13, 2024
1 parent 985d29f commit 9916352
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 30 deletions.
23 changes: 11 additions & 12 deletions src/actor/context/actor_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ impl ActorContext {
.invoke_user_message(MessageHandle::new(AutoReceiveMessage::PostRestart))
.await;
if result.is_err() {
P_LOG.error("Failed to handle Started message", vec![]).await;
P_LOG.error("Failed to handle Started message").await;
return result;
}

Expand All @@ -322,7 +322,7 @@ impl ActorContext {
let msg = extras.get_stash().await.pop().await.unwrap();
let result = self.invoke_user_message(msg).await;
if result.is_err() {
P_LOG.error("Failed to handle stashed message", vec![]).await;
P_LOG.error("Failed to handle stashed message").await;
return result;
}
}
Expand All @@ -341,7 +341,7 @@ impl ActorContext {
.invoke_user_message(MessageHandle::new(AutoReceiveMessage::PostStop))
.await;
if result.is_err() {
P_LOG.error("Failed to handle Stopped message", vec![]).await;
P_LOG.error("Failed to handle Stopped message").await;
return result;
}
let other_stopped = MessageHandle::new(SystemMessage::Terminate(TerminateInfo {
Expand Down Expand Up @@ -390,15 +390,15 @@ impl ActorContext {
self.cancel_receive_timeout().await;
let result = self.restart().await;
if result.is_err() {
P_LOG.error("Failed to restart actor", vec![]).await;
P_LOG.error("Failed to restart actor").await;
return result;
}
}
State::Stopping => {
self.cancel_receive_timeout().await;
let result = self.finalize_stop().await;
if result.is_err() {
P_LOG.error("Failed to finalize stop", vec![]).await;
P_LOG.error("Failed to finalize stop").await;
return result;
}
}
Expand Down Expand Up @@ -436,13 +436,13 @@ impl ActorContext {
.invoke_user_message(MessageHandle::new(AutoReceiveMessage::PreStop))
.await;
if result.is_err() {
P_LOG.error("Failed to handle Stopping message", vec![]).await;
P_LOG.error("Failed to handle Stopping message").await;
return result;
}
self.stop_all_children().await;
let result = self.try_restart_or_terminate().await;
if result.is_err() {
P_LOG.error("Failed to try_restart_or_terminate", vec![]).await;
P_LOG.error("Failed to try_restart_or_terminate").await;
return result;
}
tracing::debug!("ActorContext::handle_stop: finished");
Expand All @@ -462,13 +462,13 @@ impl ActorContext {
.invoke_user_message(MessageHandle::new(AutoReceiveMessage::PreRestart))
.await;
if result.is_err() {
P_LOG.error("Failed to handle Restarting message", vec![]).await;
P_LOG.error("Failed to handle Restarting message").await;
return result;
}
self.stop_all_children().await;
let result = self.try_restart_or_terminate().await;
if result.is_err() {
P_LOG.error("Failed to try_restart_or_terminate", vec![]).await;
P_LOG.error("Failed to try_restart_or_terminate").await;
return result;
}

Expand Down Expand Up @@ -534,12 +534,12 @@ impl ActorContext {
let msg = MessageHandle::new(AutoReceiveMessage::Terminated(terminated.clone()));
let result = self.invoke_user_message(msg.clone()).await;
if result.is_err() {
P_LOG.error("Failed to handle Terminated message", vec![]).await;
P_LOG.error("Failed to handle Terminated message").await;
return result;
}
let result = self.try_restart_or_terminate().await;
if result.is_err() {
P_LOG.error("Failed to try_restart_or_terminate", vec![]).await;
P_LOG.error("Failed to try_restart_or_terminate").await;
return result;
}
Ok(())
Expand Down Expand Up @@ -1105,7 +1105,6 @@ impl Supervisor for ActorContext {
"[Supervision] Actor: {}, failed with message: {}, exception: {}",
self_pid, message_handle, reason
),
vec![],
)
.await;
}
Expand Down
4 changes: 1 addition & 3 deletions src/actor/dispatch/dead_letter_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ impl DeadLetterProcess {
P_LOG
.info(
&format!("DeadLetterProcess: Throttling dead letters, count: {}", i),
vec![],
)
.await;
});
Expand Down Expand Up @@ -96,8 +95,7 @@ impl DeadLetterProcess {
.map(|v| v.to_string())
.unwrap_or("None".to_string()),
is_ignore_dead_letter,
),
vec![],
)
)
.await
}
Expand Down
4 changes: 2 additions & 2 deletions src/actor/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ impl FutureProcess {
);
if !ok {
P_LOG
.error(
.error_with_fields(
"failed to register future process",
vec![LogField::stringer("pid", pid.to_string())],
[LogField::stringer("pid", pid.to_string())],
)
.await;
}
Expand Down
4 changes: 2 additions & 2 deletions src/actor/guardian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ impl GuardianProcess {
.add_process(ph, &format!("guardian-{}", id));
if !ok {
P_LOG
.error(
.error_with_fields(
"failed to register guardian process",
vec![LogField::stringer("pid", pid.clone())],
[LogField::stringer("pid", pid.clone())],
)
.await
}
Expand Down
1 change: 0 additions & 1 deletion src/actor/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ pub static P_LOG: Lazy<Logger> = Lazy::new(|| {
get_global_log_event_stream(),
crate::log::log::Level::Debug,
"[ACTOR]",
vec![],
)
});

Expand Down
2 changes: 1 addition & 1 deletion src/actor/supervisor/supervision_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub async fn subscribe_supervision(actor_system: &ActorSystem) -> Subscription {
async move {
if let Some(supervisor_event) = evt {
P_LOG
.debug(
.debug_with_fields(
"[SUPERVISION]",
vec![
LogField::stringer("actor", supervisor_event.child.clone()),
Expand Down
18 changes: 9 additions & 9 deletions src/log/log_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod tests {
#[tokio::test]
async fn test_logger_with() {
let event_stream = LogEventStream::new();
let base = Logger::new(event_stream, Level::Debug, "", [LogField::string("first", "value")]);
let base = Logger::new(event_stream, Level::Debug, "").with_fields([LogField::string("first", "value")]);
let l = base.with_fields([LogField::string("second", "value")]);

assert_eq!(
Expand All @@ -22,8 +22,8 @@ mod tests {
#[tokio::test]
async fn test_off_level_two_fields() {
let event_stream = LogEventStream::new();
let l = Logger::new(event_stream, Level::Min, "", []);
l.debug("foo", [LogField::int("bar", 32), LogField::bool("fum", false)])
let l = Logger::new(event_stream, Level::Min, "");
l.debug_with_fields("foo", [LogField::int("bar", 32), LogField::bool("fum", false)])
.await;
}

Expand All @@ -33,10 +33,10 @@ mod tests {
let l = Logger::new(
event_stream,
Level::Min,
"",
"").with_fields(
[LogField::int("bar", 32), LogField::bool("fum", false)],
);
l.debug("foo", []).await;
l.debug("foo").await;
}

#[tokio::test]
Expand All @@ -47,10 +47,10 @@ mod tests {
let l = Logger::new(
event_stream,
Level::Debug,
"",
"").with_fields(
[LogField::int("bar", 32), LogField::bool("fum", false)],
);
l.debug("foo", []).await;
l.debug("foo").await;

unsubscribe_stream(&_s1).await;
}
Expand All @@ -64,10 +64,10 @@ mod tests {
let l = Logger::new(
event_stream,
Level::Debug,
"",
"").with_fields(
[LogField::int("bar", 32), LogField::bool("fum", false)],
);
l.debug("foo", []).await;
l.debug("foo").await;

unsubscribe_stream(&_s1).await;
unsubscribe_stream(&_s2).await;
Expand Down

0 comments on commit 9916352

Please sign in to comment.