Skip to content

Commit

Permalink
feat: Conditional logging facade (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pscheidl authored Mar 8, 2023
1 parent 2dda1cb commit c309bca
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
29 changes: 29 additions & 0 deletions src/cond_log.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#[cfg(debug_assertions)]
pub(crate) use log::debug;

#[cfg(debug_assertions)]
pub(crate) use log::trace;

#[cfg(not(debug_assertions))]
macro_rules! debug {
($($arg:tt)+) => {
// Debug logging disabled in `release` profile
};
}

#[cfg(not(debug_assertions))]
pub(crate) use debug;

#[cfg(not(debug_assertions))]
macro_rules! trace {
(target: $target:expr, $($arg:tt)+) => {
$($arg)+
// Trace logging disabled in `release` profile
};
($($arg:tt)+) => {
// Trace logging disabled in `release` profile
};
}

#[cfg(not(debug_assertions))]
pub(crate) use trace;
2 changes: 1 addition & 1 deletion src/de.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use log::debug;
use crate::cond_log::debug;
use serde::de::{DeserializeSeed, IntoDeserializer, SeqAccess, Visitor};
use serde::{de, forward_to_deserialize_any};

Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
//! println!("{:?}", t)
//! ```
mod cond_log;
mod de;
mod error;
mod value;
Expand Down
2 changes: 1 addition & 1 deletion src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::BTreeMap;
use std::fmt::{Debug, Formatter};
use std::{env, fmt};

use log::trace;
use crate::cond_log::trace;

/// Node represents a tree of env values.
///
Expand Down

0 comments on commit c309bca

Please sign in to comment.