server: misc changes for traces

This commit is contained in:
2025-12-01 13:26:44 +09:00
parent 025df3490c
commit ff858de178
3 changed files with 24 additions and 6 deletions

View File

@@ -4,6 +4,7 @@ use nix::unistd::{Group as LibcGroup, User as LibcUser};
#[cfg(not(target_os = "macos"))]
use std::ffi::CString;
use std::fmt;
pub const DEFAULT_CONFIG_PATH: &str = "/etc/muscl/config.toml";
pub const DEFAULT_SOCKET_PATH: &str = "/run/muscl/muscl.sock";
@@ -24,6 +25,12 @@ pub struct UnixUser {
pub groups: Vec<String>,
}
impl fmt::Display for UnixUser {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.username)
}
}
// TODO: these functions are somewhat critical, and should have integration tests
#[cfg(target_os = "macos")]

View File

@@ -91,9 +91,9 @@ pub async fn handle_command(
}
if auto_detected_systemd_mode {
tracing::info!("Running in systemd mode, auto-detected");
tracing::debug!("Running in systemd mode, auto-detected");
} else {
tracing::info!("Running in systemd mode");
tracing::debug!("Running in systemd mode");
}
} else {
let subscriber = tracing_subscriber::Registry::default()
@@ -111,7 +111,7 @@ pub async fn handle_command(
trace_server_prelude();
tracing::info!("Running in standalone mode");
tracing::debug!("Running in standalone mode");
}
let config_path = config_path.unwrap_or_else(|| PathBuf::from(DEFAULT_CONFIG_PATH));

View File

@@ -77,7 +77,13 @@ pub async fn session_handler(
}
};
session_handler_with_unix_user(socket, &unix_user, db_pool).await
tracing::info!("Accepted connection from user: {}", unix_user);
let result = session_handler_with_unix_user(socket, &unix_user, db_pool).await;
tracing::info!("Finished handling requests for connection from user: {}", unix_user);
result
}
pub async fn session_handler_with_unix_user(
@@ -143,7 +149,12 @@ async fn session_handler_with_db_connection(
}
request => request.to_owned(),
};
tracing::info!("Received request: {:#?}", request_to_display);
if request_to_display != Request::Exit {
tracing::info!("Received request: {:#?}", request_to_display);
} else {
tracing::debug!("Received request: {:#?}", request_to_display);
}
let response = match request {
Request::CheckAuthorization(dbs_or_users) => {
@@ -237,7 +248,7 @@ async fn session_handler_with_db_connection(
}
response => response.to_owned(),
};
tracing::info!("Response: {:#?}", response_to_display);
tracing::debug!("Response: {:#?}", response_to_display);
stream.send(response).await?;
stream.flush().await?;