Skip to content

Commit

Permalink
set_logging_level
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Jan 10, 2024
1 parent 5eeb657 commit 22cad6f
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion bin/src/command_v2/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use mio::Token;
use nom::{HexDisplay, Offset};
use sozu_command_lib::{
buffer::fixed::Buffer,
logging,
parser::parse_several_requests,
proto::command::{
request::RequestType, response_content::ContentType, AggregatedMetrics, AvailableMetrics,
Expand Down Expand Up @@ -97,7 +98,7 @@ impl Server {
RequestType::QueryMetrics(inner) => query_metrics(self, client, inner),
RequestType::SoftStop(_) => stop(self, client, false),
RequestType::HardStop(_) => stop(self, client, true),
RequestType::Logging(_) => todo!(),
RequestType::Logging(logging_filter) => set_logging_level(self, client, logging_filter),
RequestType::ReturnListenSockets(_) => todo!(), // no need to implement this
RequestType::QueryCertificatesFromTheState(filters) => {
query_certificates_from_main(self, client, filters)
Expand Down Expand Up @@ -268,6 +269,29 @@ fn save_state(server: &mut Server, client: &mut ClientSession, path: &str) {
}
}

fn set_logging_level(server: &mut Server, client: &mut ClientSession, logging_filter: String) {
debug!("Changing main process log level to {}", logging_filter);
logging::LOGGER.with(|l| {
let directives = logging::parse_logging_spec(&logging_filter);
l.borrow_mut().set_directives(directives);
});

// also change / set the content of RUST_LOG so future workers / main thread
// will have the new logging filter value
::std::env::set_var("RUST_LOG", &logging_filter);
debug!(
"Logging level now: {}",
::std::env::var("RUST_LOG").unwrap_or("could get RUST_LOG from env".to_string())
);

// notify the workers too
worker_request(
server,
client,
RequestType::Logging(logging_filter.clone()).into(),
);
}

//===============================================
// Query clusters

Expand Down

0 comments on commit 22cad6f

Please sign in to comment.