Skip to content

Commit

Permalink
tweak server logging
Browse files Browse the repository at this point in the history
  • Loading branch information
robjtede committed Oct 22, 2021
1 parent a1d15f2 commit 1c8fcae
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
8 changes: 4 additions & 4 deletions actix-server/src/accept.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use actix_rt::{
time::{sleep, Instant},
System,
};
use log::{error, info};
use log::{debug, error, info};
use mio::{Interest, Poll, Token as MioToken};

use crate::server::Server;
Expand Down Expand Up @@ -229,7 +229,7 @@ impl Accept {
WAKER_TOKEN => {
let exit = self.handle_waker(sockets);
if exit {
info!("Accept is stopped.");
info!("Accept thread stopped");
return;
}
}
Expand Down Expand Up @@ -365,14 +365,14 @@ impl Accept {

fn register_logged(&self, info: &mut ServerSocketInfo) {
match self.register(info) {
Ok(_) => info!("Resume accepting connections on {}", info.lst.local_addr()),
Ok(_) => debug!("Resume accepting connections on {}", info.lst.local_addr()),
Err(e) => error!("Can not register server socket {}", e),
}
}

fn deregister_logged(&self, info: &mut ServerSocketInfo) {
match self.poll.registry().deregister(&mut info.lst) {
Ok(_) => info!("Paused accepting connections on {}", info.lst.local_addr()),
Ok(_) => debug!("Paused accepting connections on {}", info.lst.local_addr()),
Err(e) => {
error!("Can not deregister server socket {}", e)
}
Expand Down
20 changes: 12 additions & 8 deletions actix-server/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,14 @@ impl ServerBuilder {
if self.sockets.is_empty() {
panic!("Server should have at least one bound socket");
} else {
info!("Starting {} workers", self.threads);
for (_, name, lst) in &self.sockets {
info!(
r#"Starting service: "{}", workers: {}, listening on: {}"#,
name,
self.threads,
lst.local_addr()
);
}

// start workers
let handles = (0..self.threads)
Expand All @@ -264,9 +271,6 @@ impl ServerBuilder {
.collect();

// start accept thread
for sock in &self.sockets {
info!("Starting \"{}\" service on {}", sock.1, sock.2);
}
self.accept.start(
mem::take(&mut self.sockets)
.into_iter()
Expand Down Expand Up @@ -312,7 +316,7 @@ impl ServerBuilder {
// Handle `SIGINT`, `SIGTERM`, `SIGQUIT` signals and stop actix system
match sig {
Signal::Int => {
info!("SIGINT received, starting forced shutdown");
info!("SIGINT received; starting forced shutdown");
self.exit = true;
self.handle_cmd(ServerCommand::Stop {
graceful: false,
Expand All @@ -321,7 +325,7 @@ impl ServerBuilder {
}

Signal::Term => {
info!("SIGTERM received, starting graceful shutdown");
info!("SIGTERM received; starting graceful shutdown");
self.exit = true;
self.handle_cmd(ServerCommand::Stop {
graceful: true,
Expand All @@ -330,7 +334,7 @@ impl ServerBuilder {
}

Signal::Quit => {
info!("SIGQUIT received, starting forced shutdown");
info!("SIGQUIT received; starting forced shutdown");
self.exit = true;
self.handle_cmd(ServerCommand::Stop {
graceful: false,
Expand Down Expand Up @@ -390,7 +394,7 @@ impl ServerBuilder {
}

if found {
error!("Worker has died {:?}, restarting", idx);
error!("Worker {} has died; restarting", idx);

let mut new_idx = self.handles.len();
'found: loop {
Expand Down
6 changes: 3 additions & 3 deletions actix-server/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,11 @@ impl Future for ServerWorker {
{
let num = this.counter.total();
if num == 0 {
info!("Shutting down worker, 0 connections");
info!("Shutting down idle worker");
let _ = tx.send(true);
return Poll::Ready(());
} else if graceful {
info!("Graceful worker shutdown, {} connections", num);
info!("Graceful worker shutdown; finishing {} connections", num);
this.shutdown(false);

this.state = WorkerState::Shutdown(Shutdown {
Expand All @@ -479,7 +479,7 @@ impl Future for ServerWorker {
tx,
});
} else {
info!("Force shutdown worker, {} connections", num);
info!("Force shutdown worker, closing {} connections", num);
this.shutdown(true);

let _ = tx.send(false);
Expand Down

0 comments on commit 1c8fcae

Please sign in to comment.