Skip to content

Commit

Permalink
url, logger: remove more code if debug-logging feature disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
2bc4 committed Feb 19, 2024
1 parent 53e1d3e commit e2f60bc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/http/url.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use std::{
fmt::{self, Display, Formatter},
hash::{DefaultHasher, Hasher},
ops::Deref,
};

use anyhow::{bail, Context, Result};

use crate::logger;

#[derive(Default, Clone, Debug)]
pub struct Url {
#[allow(dead_code)] //used for debug logging
Expand Down Expand Up @@ -95,7 +92,11 @@ impl Url {
}
}

#[cfg(feature = "debug-logging")]
fn hash(url: &str) -> u64 {
use crate::logger;
use std::hash::{DefaultHasher, Hasher};

if logger::is_debug() {
let mut hasher = DefaultHasher::new();
hasher.write(url.as_bytes());
Expand All @@ -105,4 +106,9 @@ impl Url {
u64::default()
}
}

#[cfg(not(feature = "debug-logging"))]
fn hash(_url: &str) -> u64 {
u64::default()
}
}
6 changes: 6 additions & 0 deletions src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,16 @@ impl Logger {
}
}

#[cfg(feature = "debug-logging")]
pub fn is_debug() -> bool {
log::max_level() == LevelFilter::Debug
}

#[cfg(not(feature = "debug-logging"))]
pub fn is_debug() -> bool {
false
}

fn level_tag_no_color(level: Level) -> &'static str {
match level {
Level::Error => "[ERROR]",
Expand Down

0 comments on commit e2f60bc

Please sign in to comment.