pub struct OpenNetLogger;Expand description
Callback-only logging. The library does not print or persist log records.
Implementations§
Source§impl OpenNetLogger
impl OpenNetLogger
Sourcepub fn register_log_listener(
listener: LogListener,
log_types: &[LogType],
) -> Result<LogSubscription>
pub fn register_log_listener( listener: LogListener, log_types: &[LogType], ) -> Result<LogSubscription>
Registers an independent subscription with a queue of 256 records.
Only explicitly listed origins are accepted, including for overflow reports. An empty type list is invalid. The returned handle must remain alive. Registration can fail if the callback thread cannot be created.
Sourcepub fn register_log_listener_with_capacity(
listener: LogListener,
log_types: &[LogType],
capacity: usize,
) -> Result<LogSubscription>
pub fn register_log_listener_with_capacity( listener: LogListener, log_types: &[LogType], capacity: usize, ) -> Result<LogSubscription>
Registers a subscription with a bounded number of queued records.
Producers never wait for queue capacity. Overflow increments
LogSubscription::dropped_count and is reported after the consumer resumes
as a synthetic log_subscription_overflow record using the first listed
origin.
Capacity must be in 1..=16_384. Zero, larger capacities and an empty
type list return io::ErrorKind::InvalidInput before allocating the
queue or starting the callback thread. The limit counts queued records,
not their payload bytes or the total memory used by all subscriptions.
Registration can also fail if the callback thread cannot be created.
Registers a subscription sharing immutable records with other listeners.
Only configured origins and levels are delivered. Exported log macros skip content parameter evaluation when no subscription needs the origin/level; another listener (including a legacy listener accepting every level) may still require construction. Concurrent subscription changes can occur after this check. Legacy listeners receive owned records at delivery time and can still require a deep copy.
Producers never wait for queue space. Records exceeding a configured limit
are dropped whole and counted by LogSubscription::drop_stats. A Debug
log_subscription_overflow report can be delivered after a callback
returns, using the first configured origin. It bypasses the queue but
obeys the subscription’s level and single-record limit. A suppressed report
does not create another drop; counters remain available independently.
Returns io::ErrorKind::InvalidInput before allocating a queue or starting
a worker for empty origins, a capacity outside 1..=16_384, zero byte
limits, or a single-record limit greater than the queued-byte limit.
Registration can also fail if the callback thread cannot be created.
use open_net::{LogLevel, LogSubscriptionOptions, LogType, OpenNetLogger};
let subscription = OpenNetLogger::register_shared_log_listener(
Box::new(|record| eprintln!("{}: {}", record.tag, record.content)),
LogSubscriptionOptions::new(&[LogType::Engine, LogType::HTTP])
.with_max_level(LogLevel::Warn),
)?;
// Keep the handle alive while logging is needed.
let oversized = subscription.drop_stats().oversized;Sourcepub fn clear_global_log_listener()
pub fn clear_global_log_listener()
Clears all global subscriptions without waiting for callbacks in progress.