Skip to main content

init

Function init 

Source
pub fn init(
    log_prefix: &str,
    log_path: &str,
    level: Level,
    max_log_files: usize,
) -> Result<LogGuard, LogInitError>
Expand description

Starts the private media-pp file logger.

Records are appended to {log_prefix}.{date}.log in log_path. Files rotate daily and only the newest max_log_files are retained. The bounded writer is lossy by design: if disk output falls behind a burst of records, the producing media thread drops that record instead of blocking. Use LogGuard::dropped_lines to inspect the count.

This does not install a global log logger or tracing subscriber. It can coexist with any logger installed by the embedding application.

The returned LogGuard must be retained for as long as logging is needed. Dropping it permanently stops this one-shot logger and makes a bounded attempt to flush what is still queued; see LogGuard for what that does and does not promise. Initialization is per process, not per guard: a second call returns LogInitError::AlreadyInitialized whether or not the first guard is still alive, so an application cannot re-enable logging or move it to a different directory afterwards. Integration tests that need this logger therefore need one test binary each, since cargo test runs a binary’s tests in one process.