diff --git a/bin/src/command/requests.rs b/bin/src/command/requests.rs index 10ec7bfd9..675d37ff7 100644 --- a/bin/src/command/requests.rs +++ b/bin/src/command/requests.rs @@ -15,7 +15,7 @@ use nom::{HexDisplay, Offset}; use sozu_command_lib::{ buffer::fixed::Buffer, config::Config, - logging, + logging::{self, change_log_level}, parser::parse_several_requests, proto::command::{ request::RequestType, response_content::ContentType, AggregatedMetrics, AvailableMetrics, @@ -1195,10 +1195,7 @@ impl CommandServer { client_id: String, ) -> anyhow::Result> { 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); - }); + logging::LOGGER.with(|logger| change_log_level(logger, &logging_filter)); // 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); diff --git a/command/src/logging.rs b/command/src/logging.rs index ebaece98e..c7efbb2ba 100644 --- a/command/src/logging.rs +++ b/command/src/logging.rs @@ -211,6 +211,11 @@ impl Logger { } } +pub fn change_log_level(logger: &RefCell, logging_filter: &str) { + let directives = parse_logging_spec(&logging_filter); + logger.borrow_mut().set_directives(directives); +} + pub enum LoggerBackend { Stdout(Stdout), Unix(UnixDatagram), diff --git a/lib/src/http.rs b/lib/src/http.rs index 19e649a5f..af12f199e 100644 --- a/lib/src/http.rs +++ b/lib/src/http.rs @@ -19,7 +19,7 @@ use slab::Slab; use time::{Duration, Instant}; use sozu_command::{ - logging, + logging::{self, change_log_level}, proto::command::{ request::RequestType, Cluster, HttpListenerConfig, ListenerType, RemoveListener, RequestHttpFrontend, @@ -700,10 +700,8 @@ impl HttpProxy { } pub fn logging(&mut self, logging_filter: String) -> Result<(), ProxyError> { - logging::LOGGER.with(|l| { - let directives = logging::parse_logging_spec(&logging_filter); - l.borrow_mut().set_directives(directives); - }); + logging::LOGGER.with(|logger| change_log_level(logger, &logging_filter)); + Ok(()) } } diff --git a/lib/src/https.rs b/lib/src/https.rs index b1c867ba3..3d31e5199 100644 --- a/lib/src/https.rs +++ b/lib/src/https.rs @@ -31,7 +31,7 @@ use time::{Duration, Instant}; use sozu_command::{ certificate::Fingerprint, config::DEFAULT_CIPHER_SUITES, - logging, + logging::{self, change_log_level}, proto::command::{ request::RequestType, response_content::ContentType, AddCertificate, CertificateSummary, CertificatesByAddress, Cluster, HttpsListenerConfig, ListOfCertificatesByAddress, @@ -913,10 +913,8 @@ impl HttpsProxy { &mut self, logging_filter: String, ) -> Result, ProxyError> { - logging::LOGGER.with(|l| { - let directives = logging::parse_logging_spec(&logging_filter); - l.borrow_mut().set_directives(directives); - }); + logging::LOGGER.with(|logger| change_log_level(logger, &logging_filter)); + Ok(None) } diff --git a/lib/src/tcp.rs b/lib/src/tcp.rs index 44cbbf581..2a2bc7c4c 100644 --- a/lib/src/tcp.rs +++ b/lib/src/tcp.rs @@ -18,7 +18,7 @@ use rusty_ulid::Ulid; use slab::Slab; use time::{Duration, Instant}; -use sozu_command::{proto::command::request::RequestType, ObjectKind}; +use sozu_command::{logging::change_log_level, proto::command::request::RequestType, ObjectKind}; use crate::{ backends::{Backend, BackendMap}, @@ -1363,10 +1363,8 @@ impl ProxyConfiguration for TcpProxy { "{} changing logging filter to {}", message.id, logging_filter ); - logging::LOGGER.with(|l| { - let directives = logging::parse_logging_spec(&logging_filter); - l.borrow_mut().set_directives(directives); - }); + logging::LOGGER.with(|logger| change_log_level(logger, &logging_filter)); + WorkerResponse::ok(message.id) } RequestType::AddCluster(cluster) => {