1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#![allow(clippy::style)]

//! # speak-easy
//!
//! Logging functionalities with different levels and rotation options built on top of tokio-rs tracing.
//!
//! ## Features
//!| Feature                          | Status |
//!|----------------------------------|--------|
//!| 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`:
//!
//! ```toml
//! [dependencies]
//! speak-easy = "0.1.0"
//! ```
//!
//! Then add this to your crate root:
//!
//!
//! You can then use the logging functionality as follows:
//!
//! ```rust
//! use speak-easy::{debug, error, info, trace, warn};
//! use speak_easy::{speak_easy::SpeakEasy, Level, Rotation, SpeakConfig};
//!
//! let config = SpeakConfig {
//!     interval: Rotation::Hourly,
//!     directory_path: "./logs".to_string(),
//!     prefix: "my_log".to_string(),
//! };
//! SpeakEasy::init(
//!     Level::INFO,
//!     Some(SpeakConfig {
//!        interval: ::speak_easy::log::Rotation::Minutely,
//!        directory_path: "./logs".to_string(),
//!        prefix: "indid".to_string(),
//!    }),
//! );
//!
//! 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.

mod formatter;
pub use tracing::{debug, error, info, trace, warn, Level};
pub mod speak_easy;
pub enum Rotation {
    Minutely,
    Hourly,
    Daily,
    Never,
}

pub struct SpeakConfig {
    pub interval: Rotation,
    pub directory_path: String,
    pub prefix: String,
}

impl Default for SpeakConfig {
    fn default() -> Self {
        Self {
            interval: Rotation::Never,
            directory_path: "./logs".to_string(),
            prefix: "log".to_string(),
        }
    }
}