#thread-safe #logs #log #logging #mutex #logger #log-level

mutex_logger

a crate for a logger that usess mutex for thread safty

2 releases (1 stable)

1.0.0 Sep 5, 2024
0.1.0 Aug 29, 2024

#648 in Concurrency

Download history 121/week @ 2024-08-24 160/week @ 2024-08-31 28/week @ 2024-09-07 45/week @ 2024-09-14 11/week @ 2024-09-21 14/week @ 2024-09-28 2/week @ 2024-10-05

63 downloads per month
Used in visa-device-handler

Custom license

14KB
195 lines

Mutex Logger

A Rust logging crate designed for multithreaded environments. MLogger uses mutex guards to ensure thread-safe logging, preventing data races when logging from multiple threads concurrently.

Features

  • Thread-Safe Logging: Uses Mutex to protect internal data structures, making it safe to log from multiple threads.
  • Configurable Verbosity Levels: Control which logs are shown based on their severity level (e.g., Error, Warn, Info, Debug).
  • Log Retention: Set a maximum number of log entries to keep, automatically discarding the oldest logs when the limit is reached.
  • Flexible API: Easily log messages, retrieve logs, and print logs at different verbosity levels.

Verbosity Levels

MLogger supports different verbosity levels to control which logs are displayed:

  • Silent: No logs are shown.
  • Error: Only error-level logs are shown.
  • Warn: Warning and error-level logs are shown.
  • Info: Information, warning, and error-level logs are shown.
  • Debug: All logs are shown, including debug-level logs.

Example


    let logger = Logger::init(Verbosity::Warn, 100);
    logger.log("this is error log!", Verbosity::Error).unwrap();
    logger.log("this is info log! it will not show!", Verbosity::Info).unwrap();
    println!("{}",logger.get_size().unwrap());

Change Log 1.0.0

  • Added color to the formated text.
  • Change the format text to show log id,colored verbosity,text.

Dependencies

~0–9.5MB
~42K SLoC