Skip to content

Commit

Permalink
command::logging::logs apply review
Browse files Browse the repository at this point in the history
  • Loading branch information
Keksoj committed Jul 17, 2024
1 parent b74888c commit 9f765c1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions command/examples/bench_logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ fn main() {
eprintln!(
"n={n}, pre_generate={pre_generate}, target={target}, colored={colored}, filter={filter}"
);
if let Err(e) = setup_logging(&target, colored, None, None, None, &filter, "WRK-01") {
println!("could not setup logging: {}", e);
if let Err(e) = setup_logging(&target, colored, None, None, None, &filter, "BENCH") {
println!("Could not setup logging: {}", e);
}

let mut pre_generated_log_iterator;
Expand Down
25 changes: 11 additions & 14 deletions command/src/logging/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ impl Logger {
access_format: Option<AccessLogFormat>,
access_colored: Option<bool>,
) -> Result<(), LogError> {
println!("setting log target to {log_target}");
println!("Logs will be sent to {log_target}");
let backend = target_or_default(log_target);

println!("setting target of access logs to {access_logs_target:?}");
println!("Access logs will be sent to {access_logs_target:?}");
let access_backend = access_logs_target.map(target_to_backend).transpose()?;

let (directives, _errors) = parse_logging_spec(spec);
Expand Down Expand Up @@ -303,10 +303,13 @@ impl InnerLogger {
if let Err(e) = io_result {
println!("Could not write access log to {}: {e:?}", backend.as_ref());
println!(
"trying to revive the backend of access logs to {:?}, or defaulting to {}",
"Trying to revive the backend of access logs to {:?}, or defaulting to {}",
self.access_logs_target, self.log_target
);
backend.revive(self.access_logs_target.as_ref().unwrap_or(&self.log_target));
let log_target = self.access_logs_target.as_ref().unwrap_or(&self.log_target);
if let Err(err) = backend.revive(log_target) {
eprintln!("could not revive logger backend: {err}");
}
false
} else {
true
Expand Down Expand Up @@ -345,13 +348,9 @@ pub enum LoggerBackend {
}

impl LoggerBackend {
fn revive(&mut self, log_target: &str) {
match target_to_backend(log_target) {
Ok(backend) => *self = backend,
Err(err) => {
eprintln!("could not revive logger backend: {err}");
}
}
fn revive(&mut self, log_target: &str) -> Result<(), LogError> {
*self = target_to_backend(log_target)?;
Ok(())
}
}

Expand Down Expand Up @@ -636,11 +635,9 @@ pub fn setup_logging(
log_level: &str,
tag: &str,
) -> Result<(), LogError> {
let log_level = env::var("RUST_LOG").unwrap_or(log_level.to_string());

Logger::init(
tag.to_string(),
&log_level,
env::var("RUST_LOG").as_deref().unwrap_or(log_level),
log_target,
log_colored,
access_logs_target,
Expand Down

0 comments on commit 9f765c1

Please sign in to comment.