summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2020-12-11 20:39:32 -0500
committerGitHub <noreply@github.com>2020-12-11 20:39:32 -0500
commit766fe25c55b1a3776dc94daccbe0505c5cdfb0a1 (patch)
treeb49cbe49c8e0913f569d6e1ed8cfc663cdcac033 /src
parent8c4ad90e6756a006243f04033ae9bd9bc9e2f095 (diff)
refactor: Use feature flags to avoid building with fern and log (#351)
Diffstat (limited to 'src')
-rw-r--r--src/bin/main.rs3
-rw-r--r--src/lib.rs1
-rw-r--r--src/utils/error.rs1
-rw-r--r--src/utils/logging.rs5
4 files changed, 6 insertions, 4 deletions
diff --git a/src/bin/main.rs b/src/bin/main.rs
index 320b100a..8df793a7 100644
--- a/src/bin/main.rs
+++ b/src/bin/main.rs
@@ -1,5 +1,6 @@
#![warn(rust_2018_idioms)]
#[allow(unused_imports)]
+#[cfg(feature = "log")]
#[macro_use]
extern crate log;
@@ -33,7 +34,7 @@ fn main() -> Result<()> {
// tmp_dir.push("bottom_debug.log");
// utils::logging::init_logger(log::LevelFilter::Trace, tmp_dir.as_os_str())?;
// } else {
- #[cfg(debug_assertions)]
+ #[cfg(all(feature = "fern", debug_assertions))]
{
utils::logging::init_logger(log::LevelFilter::Debug, std::ffi::OsStr::new("debug.log"))?;
}
diff --git a/src/lib.rs b/src/lib.rs
index e245f1ef..1f10990e 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,6 @@
#![warn(rust_2018_idioms)]
#[allow(unused_imports)]
+#[cfg(feature = "log")]
#[macro_use]
extern crate log;
diff --git a/src/utils/error.rs b/src/utils/error.rs
index 8bfec098..861fc101 100644
--- a/src/utils/error.rs
+++ b/src/utils/error.rs
@@ -73,6 +73,7 @@ impl From<toml::de::Error> for BottomError {
}
}
+#[cfg(feature = "fern")]
impl From<fern::InitError> for BottomError {
fn from(err: fern::InitError) -> Self {
BottomError::FernError(err.to_string())
diff --git a/src/utils/logging.rs b/src/utils/logging.rs
index 86a55656..704f6434 100644
--- a/src/utils/logging.rs
+++ b/src/utils/logging.rs
@@ -1,7 +1,6 @@
-use std::ffi::OsStr;
-
+#[cfg(feature = "fern")]
pub fn init_logger(
- min_level: log::LevelFilter, debug_file_name: &OsStr,
+ min_level: log::LevelFilter, debug_file_name: &std::ffi::OsStr,
) -> Result<(), fern::InitError> {
fern::Dispatch::new()
.format(|out, message, record| {