diff --git a/gstreamer/Cargo.toml b/gstreamer/Cargo.toml index 7324a7566..214964006 100644 --- a/gstreamer/Cargo.toml +++ b/gstreamer/Cargo.toml @@ -23,7 +23,7 @@ num-rational = { version = "0.4", default-features = false, features = [] } futures-core = "0.3" futures-channel = "0.3" futures-util = { version = "0.3", default-features = false } -log = "0.4" +log = { version = "0.4", optional = true } muldiv = "1" opt-ops = { package = "option-operations", version = "0.5" } serde = { version = "1.0", optional = true, features = ["derive"] } @@ -49,6 +49,7 @@ v1_20 = ["ffi/v1_20", "v1_18"] v1_22 = ["ffi/v1_22", "v1_20"] v1_24 = ["ffi/v1_24", "v1_22"] serde = ["num-rational/serde", "dep:serde", "serde_bytes"] +log = ["dep:log"] [package.metadata.docs.rs] all-features = true diff --git a/gstreamer/src/lib.rs b/gstreamer/src/lib.rs index 71b499e27..d3cf22f01 100644 --- a/gstreamer/src/lib.rs +++ b/gstreamer/src/lib.rs @@ -49,13 +49,15 @@ mod serde_macros; #[macro_use] pub mod log; +#[cfg(feature = "log")] +pub use crate::log::DebugCategoryLogger; pub use crate::log::{ - DebugCategory, DebugCategoryLogger, DebugLogFunction, DebugMessage, LoggedObject, CAT_BUFFER, - CAT_BUFFER_LIST, CAT_BUS, CAT_CALL_TRACE, CAT_CAPS, CAT_CLOCK, CAT_CONTEXT, CAT_DEFAULT, - CAT_ELEMENT_PADS, CAT_ERROR_SYSTEM, CAT_EVENT, CAT_GST_INIT, CAT_LOCKING, CAT_MEMORY, - CAT_MESSAGE, CAT_META, CAT_NEGOTIATION, CAT_PADS, CAT_PARAMS, CAT_PARENTAGE, CAT_PERFORMANCE, - CAT_PIPELINE, CAT_PLUGIN_INFO, CAT_PLUGIN_LOADING, CAT_PROBE, CAT_PROPERTIES, CAT_QOS, - CAT_REFCOUNTING, CAT_REGISTRY, CAT_RUST, CAT_SCHEDULING, CAT_SIGNAL, CAT_STATES, + DebugCategory, DebugLogFunction, DebugMessage, LoggedObject, CAT_BUFFER, CAT_BUFFER_LIST, + CAT_BUS, CAT_CALL_TRACE, CAT_CAPS, CAT_CLOCK, CAT_CONTEXT, CAT_DEFAULT, CAT_ELEMENT_PADS, + CAT_ERROR_SYSTEM, CAT_EVENT, CAT_GST_INIT, CAT_LOCKING, CAT_MEMORY, CAT_MESSAGE, CAT_META, + CAT_NEGOTIATION, CAT_PADS, CAT_PARAMS, CAT_PARENTAGE, CAT_PERFORMANCE, CAT_PIPELINE, + CAT_PLUGIN_INFO, CAT_PLUGIN_LOADING, CAT_PROBE, CAT_PROPERTIES, CAT_QOS, CAT_REFCOUNTING, + CAT_REGISTRY, CAT_RUST, CAT_SCHEDULING, CAT_SIGNAL, CAT_STATES, }; #[cfg(target_os = "macos")] diff --git a/gstreamer/src/log.rs b/gstreamer/src/log.rs index c3c1b7441..9479432e3 100644 --- a/gstreamer/src/log.rs +++ b/gstreamer/src/log.rs @@ -4,6 +4,7 @@ use std::{borrow::Cow, ffi::CStr, fmt, ptr}; use glib::{ffi::gpointer, prelude::*, translate::*}; use libc::c_char; +#[cfg(feature = "log")] use log; use once_cell::sync::Lazy; @@ -1065,15 +1066,18 @@ macro_rules! log_with_level( }}; ); +#[cfg(feature = "log")] #[derive(Debug)] pub struct DebugCategoryLogger(DebugCategory); +#[cfg(feature = "log")] impl DebugCategoryLogger { pub fn new(cat: DebugCategory) -> Self { Self(cat) } } +#[cfg(feature = "log")] impl log::Log for DebugCategoryLogger { fn enabled(&self, _metadata: &log::Metadata) -> bool { true @@ -1346,6 +1350,7 @@ mod tests { memdump!(cat, obj: obj, "meh"); } + #[cfg(feature = "log")] static LOGGER: Lazy = Lazy::new(|| { DebugCategoryLogger::new(DebugCategory::new( "Log_trait", @@ -1355,6 +1360,7 @@ mod tests { }); #[test] + #[cfg(feature = "log")] fn log_trait() { crate::init().unwrap();