Struct LogContext
Sourcepub struct LogContext(/* private fields */);
Expand description
A context for controlling logging behavior, for example to handle logging once or periodic logging, avoiding to spam the terminal with the same log message multiple times.
§Simple log context using static macros
⚠️ The following code is in c ⚠️
// At global/file scope:
GST_LOG_CONTEXT_STATIC_DEFINE(my_context, GST_LOG_CONTEXT_FLAG_THROTTLE, );
#define MY_CONTEXT GST_LOG_CONTEXT_LAZY_INIT(my_context)
// Then in code:
GST_CTX_INFO(MY_CONTEXT, "This will only appear once per file/line");
§Periodic logging
For messages that should be logged periodically (e.g., maximum once per minute):
⚠️ The following code is in c ⚠️
// At global/file scope:
GST_LOG_CONTEXT_STATIC_DEFINE(my_periodic_context, GST_LOG_CONTEXT_FLAG_THROTTLE,
GST_LOG_CONTEXT_BUILDER_SET_INTERVAL(60 * GST_SECOND);
);
#define MY_PERIODIC_CONTEXT GST_LOG_CONTEXT_LAZY_INIT(my_periodic_context)
// Then in code:
GST_CTX_INFO(MY_PERIODIC_CONTEXT, "This appears once per minute");
§Customizing Message hash with custom flags and category
By default, a message’s hash is determined by the file name, object pointer, and format string. You can customize this with builder operations:
⚠️ The following code is in c ⚠️
// Ignore the object pointer when determining message hash (with throttling)
GST_LOG_CONTEXT_STATIC_DEFINE(obj_independent_ctx, GST_LOG_CONTEXT_FLAG_THROTTLE,
GST_LOG_CONTEXT_BUILDER_SET_HASH_FLAGS(GST_LOG_CONTEXT_IGNORE_OBJECT);
);
// Use a custom category (without throttling)
GST_LOG_CONTEXT_STATIC_DEFINE(custom_cat_ctx, GST_LOG_CONTEXT_FLAG_NONE,
GST_LOG_CONTEXT_BUILDER_SET_CATEGORY(my_category);
);
Implementations§
Source§impl LogContext
impl LogContext
Sourcepub fn category(&self) -> DebugCategory
pub fn category(&self) -> DebugCategory
Get the DebugCategory
associated with this log context.
§Returns
the DebugCategory
to which the context is bound
pub fn as_ptr(&self) -> *mut GstLogContext
pub fn log( &self, obj: Option<&impl IsA<Object>>, level: DebugLevel, file: &GStr, function: &str, line: u32, args: Arguments<'_>, )
pub fn log_literal( &self, obj: Option<&impl IsA<Object>>, level: DebugLevel, file: &GStr, function: &str, line: u32, msg: &GStr, )
pub fn log_id( &self, id: impl AsRef<GStr>, level: DebugLevel, file: &GStr, function: &str, line: u32, args: Arguments<'_>, )
pub fn log_id_literal( &self, id: impl AsRef<GStr>, level: DebugLevel, file: &GStr, function: &str, line: u32, msg: &GStr, )
Trait Implementations§
Source§impl Debug for LogContext
impl Debug for LogContext
Source§impl DebugLogger for LogContext
impl DebugLogger for LogContext
Source§fn log_id_literal_unfiltered(
&self,
id: impl AsRef<GStr>,
level: DebugLevel,
file: &GStr,
function: &str,
line: u32,
msg: &GStr,
)
fn log_id_literal_unfiltered( &self, id: impl AsRef<GStr>, level: DebugLevel, file: &GStr, function: &str, line: u32, msg: &GStr, )
Logs without checking the log level.
fn above_threshold(&self, level: DebugLevel) -> bool
fn log_unfiltered( &self, obj: Option<&impl IsA<Object>>, level: DebugLevel, file: &GStr, function: &str, line: u32, args: Arguments<'_>, )
fn log_literal_unfiltered( &self, obj: Option<&impl IsA<Object>>, level: DebugLevel, file: &GStr, function: &str, line: u32, msg: &GStr, )
fn log_id_unfiltered( &self, id: impl AsRef<GStr>, level: DebugLevel, file: &GStr, function: &str, line: u32, args: Arguments<'_>, )
Source§impl Drop for LogContext
impl Drop for LogContext
impl Send for LogContext
impl Sync for LogContext
Auto Trait Implementations§
impl Freeze for LogContext
impl RefUnwindSafe for LogContext
impl Unpin for LogContext
impl UnwindSafe for LogContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more