Crate speak_easy

source ·
Expand description

§speak-easy

Logging functionalities with different levels and rotation options built on top of tokio-rs tracing.

§Features

FeatureStatus
Console logging
File logging
Rotation options
Dispatch logs to multiple destinations

§Modules

  • formatter: This module contains the functionality for formatting the logs.
  • log_levels: This module defines the different levels of logging.
  • speak_easy: This module contains the functionality for the SpeakEasy logging system.

§Enums

  • Rotation: Defines the rotation options for the logs. Options are Minutely, Hourly, Daily, and Never.

§Structs

  • SpeakConfig: Defines the configuration for the SpeakEasy logging system. It includes the rotation interval, the directory path for the logs, and the prefix for the log files.

§Usage

Add the following to your Cargo.toml:

[dependencies]
speak-easy = "0.1.1"
tokio = { features = ["macros", "rt-multi-thread"], version = "1.37.0" }

Remeber that the tokio dependency is required for the tracing crate. Your main function should look like this:

#[tokio::main]
async fn main() {
   // Your code here
}

Then add this to your crate root:

use speak_easy::{debug, error, info, trace, warn};
use speak_easy::{speak_easy::SpeakEasy, Level, Rotation, SpeakConfig};

You can then use the logging functionality as follows:

let speak_config = SpeakConfig::new(Rotation::Minutely, "./logs".to_string(), "my_log".to_string());
SpeakEasy::init(
    Level::INFO,
    Some(speak_config),
);

info!("This is an info log");
debug!("This is a debug log");
warn!("This is a warning log");
error!("This is an error log");
trace!("This is a trace log");

This will create logs with different levels and rotate them hourly.

§With Cleanup

You can also set up log cleanup with the with_cleanup method:

let speak_config = SpeakConfig::new(Rotation::Minutely, "./logs".to_string(), "my_log".to_string())
   .with_cleanup(24 * 60 * 60, 5);
SpeakEasy::init(
   Level::INFO,
  Some(speak_config),
);

This will create logs with different levels, rotate them minutely, and clean up the logs every 24 hours, keeping the last 5 logs.

§License

This project is licensed under the MIT license.

§Contributing

Feel free to open issues and send PRs. We will evaluate them together in the comment section.

Modules§

Macros§

  • Constructs an event at the debug level.
  • Constructs an event at the error level.
  • Constructs an event at the info level.
  • Constructs an event at the trace level.
  • Constructs an event at the warn level.

Structs§

Enums§