Skip to content

Commit

Permalink
isolate change_log_level function
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Oct 18, 2023
1 parent 641daa3 commit 58b2590
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 20 deletions.
7 changes: 2 additions & 5 deletions bin/src/command/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -1195,10 +1195,7 @@ impl CommandServer {
client_id: String,
) -> anyhow::Result<Option<Success>> {
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);
Expand Down
5 changes: 5 additions & 0 deletions command/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,11 @@ impl Logger {
}
}

pub fn change_log_level(logger: &RefCell<Logger>, logging_filter: &str) {
let directives = parse_logging_spec(&logging_filter);
logger.borrow_mut().set_directives(directives);
}

pub enum LoggerBackend {
Stdout(Stdout),
Unix(UnixDatagram),
Expand Down
8 changes: 3 additions & 5 deletions lib/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(())
}
}
Expand Down
8 changes: 3 additions & 5 deletions lib/src/https.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -913,10 +913,8 @@ impl HttpsProxy {
&mut self,
logging_filter: String,
) -> Result<Option<ResponseContent>, 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)
}

Expand Down
8 changes: 3 additions & 5 deletions lib/src/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 58b2590

Please sign in to comment.