Skip to content

Commit

Permalink
Allow logging as optional feature (#26)
Browse files Browse the repository at this point in the history
* Allow logging as optional feature

* Bump v0.3.4

---------

Co-authored-by: Caleb Leinz <caleb.leinz@atlasground.com>
  • Loading branch information
cmleinz and caleb-leinz authored Jan 25, 2024
1 parent 01960f4 commit f451cfe
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
9 changes: 7 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "stubborn-io"
version = "0.3.3"
version = "0.3.4"
authors = ["David Raifaizen <david.raifaizen@protonmail.com>"]
edition = "2021"
description = "io traits/structs that automatically recover from potential disconnections/interruptions."
Expand All @@ -12,10 +12,15 @@ readme = "README.md"

[dependencies]
tokio = { version = "1", features = ["time", "net"] }
log = "0.4"
rand = "0.8"

log = { version = "0.4", optional = true }

[dev-dependencies]
tokio = { version = "1", features = ["macros", "rt", "fs", "io-util"] }
tokio-util = { version = "0.7", features = ["codec"] }
futures = "0.3"

[features]
default = ["log"]
log = ["dep:log"]
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
//! ```

pub mod config;
mod log;
pub mod strategies;

// in the future, there may be a mod for synchronous regular io too, which is why
Expand Down
69 changes: 69 additions & 0 deletions src/log.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#[allow(unused_macros)]
macro_rules! trace {
($($arg:expr),*) => {
#[cfg(feature = "log")]
log::trace!($($arg),*);
#[cfg(not(feature = "log"))]
{
$(
let _ = $arg;
)*
}
};
}

#[allow(unused_macros)]
macro_rules! debug {
($($arg:expr),*) => {
#[cfg(feature = "log")]
log::debug!($($arg),*);
#[cfg(not(feature = "log"))]
{
$(
let _ = $arg;
)*
}
};
}

macro_rules! info {
($($arg:expr),*) => {
#[cfg(feature = "log")]
log::info!($($arg),*);
#[cfg(not(feature = "log"))]
{
$(
let _ = $arg;
)*
}
};
}

#[allow(unused_macros)]
macro_rules! warn {
($($arg:expr),*) => {
#[cfg(feature = "log")]
log::warn!($($arg),*);
#[cfg(not(feature = "log"))]
{
$(
let _ = $arg;
)*
}
};
}

macro_rules! error {
($($arg:expr),*) => {
#[cfg(feature = "log")]
log::error!($($arg),*);
#[cfg(not(feature = "log"))]
{
$(
let _ = $arg;
)*
}
};
}

pub(crate) use {error, info};
2 changes: 1 addition & 1 deletion src/tokio/io.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::config::ReconnectOptions;
use log::{error, info};
use crate::log::{error, info};
use std::future::Future;
use std::io::{self, ErrorKind, IoSlice};
use std::marker::PhantomData;
Expand Down

0 comments on commit f451cfe

Please sign in to comment.