diff --git a/Cargo.lock b/Cargo.lock
index 5a6f3111..40ee30b3 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -191,7 +191,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c2f7349907b712260e64b0afe2f84692af14a454be26187d9df565c7f69266a"
dependencies = [
"memchr",
- "regex-automata",
+ "regex-automata 0.3.9",
"serde",
]
@@ -272,9 +272,9 @@ dependencies = [
[[package]]
name = "clap"
-version = "4.4.6"
+version = "4.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956"
+checksum = "ac495e00dcec98c83465d5ad66c5c4fabd652fd6686e7c6269b117e729a6f17b"
dependencies = [
"clap_builder",
"clap_derive",
@@ -282,22 +282,22 @@ dependencies = [
[[package]]
name = "clap_builder"
-version = "4.4.6"
+version = "4.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45"
+checksum = "c77ed9a32a62e6ca27175d00d29d05ca32e396ea1eb5fb01d8256b669cec7663"
dependencies = [
"anstream",
"anstyle",
- "clap_lex 0.5.1",
+ "clap_lex 0.6.0",
"strsim",
"terminal_size",
]
[[package]]
name = "clap_derive"
-version = "4.4.2"
+version = "4.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873"
+checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
dependencies = [
"heck",
"proc-macro2",
@@ -316,9 +316,9 @@ dependencies = [
[[package]]
name = "clap_lex"
-version = "0.5.1"
+version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961"
+checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
[[package]]
name = "colorchoice"
@@ -332,7 +332,7 @@ version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82c995deda3bfdebd07d0e2af79e9da13e4b1be652b21a746f3f5b24bf0a49ef"
dependencies = [
- "clap 4.4.6",
+ "clap 4.4.7",
"derive_builder",
"entities",
"memchr",
@@ -399,7 +399,7 @@ dependencies = [
"anes",
"cast",
"ciborium",
- "clap 4.4.6",
+ "clap 4.4.7",
"criterion-plot",
"is-terminal",
"itertools 0.10.5",
@@ -1242,15 +1242,6 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf"
-[[package]]
-name = "openssl-src"
-version = "300.1.5+3.1.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "559068e4c12950d7dcaa1857a61725c0d38d4fc03ff8e070ab31a75d6e316491"
-dependencies = [
- "cc",
-]
-
[[package]]
name = "openssl-sys"
version = "0.9.93"
@@ -1259,7 +1250,6 @@ checksum = "db4d56a4c0478783083cfafcc42493dd4a981d41669da64b4572a2a089b51b1d"
dependencies = [
"cc",
"libc",
- "openssl-src",
"pkg-config",
"vcpkg",
]
@@ -1411,9 +1401,9 @@ dependencies = [
[[package]]
name = "quick-xml"
-version = "0.30.0"
+version = "0.31.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "eff6510e86862b57b210fd8cbe8ed3f0d7d600b9c2863cd4549a2e033c66e956"
+checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33"
dependencies = [
"memchr",
]
@@ -1479,23 +1469,23 @@ dependencies = [
[[package]]
name = "redox_syscall"
-version = "0.3.5"
+version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29"
+checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa"
dependencies = [
"bitflags 1.3.2",
]
[[package]]
name = "regex"
-version = "1.9.6"
+version = "1.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ebee201405406dbf528b8b672104ae6d6d63e6d118cb10e4d51abbc7b58044ff"
+checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343"
dependencies = [
"aho-corasick 1.1.1",
"memchr",
- "regex-automata",
- "regex-syntax",
+ "regex-automata 0.4.3",
+ "regex-syntax 0.8.2",
]
[[package]]
@@ -1503,10 +1493,16 @@ name = "regex-automata"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9"
+
+[[package]]
+name = "regex-automata"
+version = "0.4.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f"
dependencies = [
"aho-corasick 1.1.1",
"memchr",
- "regex-syntax",
+ "regex-syntax 0.8.2",
]
[[package]]
@@ -1515,6 +1511,12 @@ version = "0.7.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da"
+[[package]]
+name = "regex-syntax"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
+
[[package]]
name = "reqwest"
version = "0.11.22"
@@ -1576,9 +1578,9 @@ dependencies = [
[[package]]
name = "rustix"
-version = "0.38.15"
+version = "0.38.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d2f9da0cbd88f9f09e7814e388301c8414c51c62aa6ce1e4b5c551d49d96e531"
+checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3"
dependencies = [
"bitflags 2.4.0",
"errno",
@@ -1654,18 +1656,18 @@ checksum = "ad977052201c6de01a8ef2aa3378c4bd23217a056337d1d6da40468d267a4fb0"
[[package]]
name = "serde"
-version = "1.0.188"
+version = "1.0.190"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
+checksum = "91d3c334ca1ee894a2c6f6ad698fe8c435b76d504b13d436f0685d648d6d96f7"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
-version = "1.0.188"
+version = "1.0.190"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
+checksum = "67c5609f394e5c2bd7fc51efda478004ea80ef42fee983d5c67a65e34f32c0e3"
dependencies = [
"proc-macro2",
"quote",
@@ -1674,9 +1676,9 @@ dependencies = [
[[package]]
name = "serde_json"
-version = "1.0.107"
+version = "1.0.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6b420ce6e3d8bd882e9b243c6eed35dbc9a6110c9769e74b584e0d68d1f20c65"
+checksum = "3d1c7e3eac408d115102c4c24ad393e0821bb3a5df4d506a80f85f7a742a526b"
dependencies = [
"itoa",
"ryu",
@@ -1685,9 +1687,9 @@ dependencies = [
[[package]]
name = "serde_spanned"
-version = "0.6.3"
+version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186"
+checksum = "12022b835073e5b11e90a14f86838ceb1c8fb0325b72416845c487ac0fa95e80"
dependencies = [
"serde",
]
@@ -1706,9 +1708,9 @@ dependencies = [
[[package]]
name = "serde_yaml"
-version = "0.9.25"
+version = "0.9.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1a49e178e4452f45cb61d0cd8cebc1b0fafd3e41929e996cef79aa3aca91f574"
+checksum = "3cc7a1570e38322cfe4154732e5110f887ea57e22b76f4bfd32b5bdd3368666c"
dependencies = [
"indexmap 2.0.2",
"itoa",
@@ -1773,17 +1775,16 @@ dependencies = [
[[package]]
name = "ssg"
-version = "0.0.19"
+version = "0.0.20"
dependencies = [
"assert_cmd",
- "clap 4.4.6",
+ "clap 4.4.7",
"comrak",
"criterion",
"dtt",
"log",
"minify-html",
- "openssl",
- "quick-xml 0.30.0",
+ "quick-xml 0.31.0",
"regex",
"reqwest",
"serde",
@@ -1837,7 +1838,7 @@ dependencies = [
"once_cell",
"onig",
"plist",
- "regex-syntax",
+ "regex-syntax 0.7.5",
"serde",
"serde_json",
"thiserror",
@@ -1868,9 +1869,9 @@ dependencies = [
[[package]]
name = "tempfile"
-version = "3.8.0"
+version = "3.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef"
+checksum = "7ef1adac450ad7f4b3c28589471ade84f25f731a7a0fe30d71dfa9f60fd808e5"
dependencies = [
"cfg-if",
"fastrand",
@@ -2025,9 +2026,9 @@ dependencies = [
[[package]]
name = "toml"
-version = "0.8.2"
+version = "0.8.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "185d8ab0dfbb35cf1399a6344d8484209c088f75f8f68230da55d48d95d43e3d"
+checksum = "8ff9e3abce27ee2c9a37f9ad37238c1bdd4e789c84ba37df76aa4d528f5072cc"
dependencies = [
"serde",
"serde_spanned",
@@ -2037,18 +2038,18 @@ dependencies = [
[[package]]
name = "toml_datetime"
-version = "0.6.3"
+version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b"
+checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
dependencies = [
"serde",
]
[[package]]
name = "toml_edit"
-version = "0.20.2"
+version = "0.20.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338"
+checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81"
dependencies = [
"indexmap 2.0.2",
"serde",
diff --git a/Cargo.toml b/Cargo.toml
index 38ce5cb6..8dd619c2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -20,7 +20,7 @@ name = "ssg"
readme = "README.md"
repository = "https://github.com/sebastienrousseau/shokunin"
rust-version = "1.71.1"
-version = "0.0.19"
+version = "0.0.20"
include = [
"/CONTRIBUTING.md",
"/LICENSE-APACHE",
@@ -46,20 +46,20 @@ harness = false
path = "benches/bench.rs"
[dependencies]
-clap = "4.4.6"
+clap = "4.4.7"
comrak = "0.19.0"
dtt = "0.0.4"
log = {version="0.4.20", features = ["std"] }
minify-html = "0.11.1"
-openssl = { version = "0.10.57", features = ["vendored"] }
-quick-xml = "0.30.0"
-regex = "1.9.6"
+# openssl = { version = "0.10.57", features = ["vendored"] }
+quick-xml = "0.31.0"
+regex = "1.10.2"
reqwest = { version = "0.11.22", features = ["blocking", "json"] }
-serde = { version = "1.0.188", features = ["derive"] }
-serde_json = "1.0.107"
-serde_yaml = "0.9.25"
-tempfile = "3.8.0"
-toml = "0.8.2"
+serde = { version = "1.0.190", features = ["derive"] }
+serde_json = "1.0.108"
+serde_yaml = "0.9.27"
+tempfile = "3.8.1"
+toml = "0.8.6"
yaml-rust = "0.4.5"
vrd = "0.0.4"
diff --git a/README.md b/README.md
index 9af714cc..332f334f 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,7 @@
-# Shokunin Static Site Generator
+# Shokunin Static Site Generator (SSG)
A Content-First Open Source Static Site Generator (SSG) written in Rust
@@ -55,7 +55,7 @@ Shokunin Static Site Generator (SSG) feature highlights include:
## Table of Contents
-- [Shokunin Static Site Generator](#shokunin-static-site-generator)
+- [Shokunin Static Site Generator (SSG)](#shokunin-static-site-generator-ssg)
- [Overview](#overview)
- [Features](#features)
- [Table of Contents](#table-of-contents)
@@ -72,7 +72,7 @@ Shokunin Static Site Generator (SSG) feature highlights include:
- [In your project](#in-your-project)
- [Examples](#examples)
- [Args](#args)
- - [Semantic Versioning Policy 🚥](#semantic-versioning-policy-)
+ - [Semantic Versioning Policy](#semantic-versioning-policy)
- [License](#license)
- [Contribution](#contribution)
- [Acknowledgements](#acknowledgements)
@@ -101,9 +101,9 @@ ssg --help
### Requirements
-The minimum supported Rust toolchain version is currently Rust
-**1.72.0** or later (stable). It is recommended that you install the
-latest stable version of Rust.
+The minimum supported Rust toolchain version is currently Rust **1.71.1** or
+later (stable). It is recommended that you install the latest stable version of
+Rust.
### Platform support
@@ -181,7 +181,7 @@ To use the Shokunin Static Site Generator (SSG) library in your project, add the
```toml
[dependencies]
-shokunin = "0.0.19"
+shokunin = "0.0.20"
```
Add the following to your `main.rs` file:
@@ -231,7 +231,7 @@ The main() function in this code compiles a website from the `content` directory
- `site_path:` The path to the directory where the generated website files will be served from.
- `template_path:` The path to the directory containing the website templates.
-## Semantic Versioning Policy 🚥
+## Semantic Versioning Policy
For transparency into our release cycle and in striving to maintain backward compatibility, Shokunin Static Site Generator (SSG) follows [semantic versioning][7].
diff --git a/src/lib.rs b/src/lib.rs
index e7196bef..15a42651 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -66,7 +66,7 @@
//!
//! ```toml
//! [dependencies]
-//! shokunin = "0.0.19"
+//! shokunin = "0.0.20"
//! ```
//!
//! And in your `main.rs`:
diff --git a/src/loggers.rs b/src/loggers.rs
index 4c6ded46..faab2db2 100644
--- a/src/loggers.rs
+++ b/src/loggers.rs
@@ -4,16 +4,15 @@
// Standard library imports for formatting and I/O operations.
use std::{
fmt,
- io::{self, Write as IoWrite},
fs::OpenOptions,
+ io::{self, Write as IoWrite},
};
-
/// Enum representing the different log formats that can be used.
///
/// This enum allows the developer to specify the format in which log messages should be displayed.
///
-#[derive(Debug, PartialEq, Eq, Hash, Clone)]
+#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, PartialOrd)]
pub enum LogFormat {
/// The log format is set to the Common Log Format (CLF)
CLF,
@@ -29,12 +28,12 @@ pub enum LogFormat {
GELF,
}
-/// Implements Display trait for LogFormat enum.
+/// Implements Display trait for `LogFormat` enum.
///
/// This allows easy conversion of the log format enums to strings.
impl fmt::Display for LogFormat {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- writeln!(f, "{:?}", self)
+ writeln!(f, "{self:?}")
}
}
@@ -55,7 +54,7 @@ impl fmt::Display for LogFormat {
/// * `VERBOSE` - The log level is set to verbose.
/// * `WARNING` - The log level is set to warning.
///
-#[derive(Debug, PartialEq, Eq, Hash, Clone,PartialOrd)]
+#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy, PartialOrd)]
pub enum LogLevel {
/// The log level is set to all.
ALL,
@@ -83,7 +82,7 @@ pub enum LogLevel {
/// This converts the enum to a string representation.
impl fmt::Display for LogLevel {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- write!(f, "{:?}", self)
+ write!(f, "{self:?}")
}
}
@@ -120,31 +119,41 @@ impl Log {
pub fn log(&self) -> io::Result<()> {
// Open the file in append mode. If the file does not exist, create it.
let mut file = OpenOptions::new()
- .write(true)
- .truncate(true)
- .open("shokunin.log")?;
+ .write(true)
+ .truncate(true)
+ .open("shokunin.log")?;
match self.format {
LogFormat::CLF => {
writeln!(
file,
"SessionID={}\tTimestamp={}\tDescription={}\tLevel={}\tComponent={}\tFormat={}",
- self.session_id, self.time, self.description, self.level, self.component, self.format
+ self.session_id,
+ self.time,
+ self.description,
+ self.level,
+ self.component,
+ self.format
)
- },
+ }
LogFormat::JSON => {
writeln!(
file,
r#"{{"session_id": "{}", "timestamp": "{}", "description": "{}", "level": "{}", "component": "{}", "format": "{}"}}"#,
- self.session_id, self.time, self.description, self.level, self.component, self.format
+ self.session_id,
+ self.time,
+ self.description,
+ self.level,
+ self.component,
+ self.format
)
- },
+ }
LogFormat::CEF => {
writeln!(
file,
r#"[CEF]
1
- shokunin
+ Shokunin
Application
{}
Log
@@ -161,10 +170,16 @@ impl Log {
-
"#,
- self.time, self.level, self.description, self.session_id
+ self.time,
+ self.level,
+ self.description,
+ self.session_id
)
- },
- _ => Err(io::Error::new(io::ErrorKind::InvalidInput, "Unsupported log format")),
+ }
+ _ => Err(io::Error::new(
+ io::ErrorKind::InvalidInput,
+ "Unsupported log format",
+ )),
}?;
file.flush()?;
Ok(())
@@ -204,10 +219,10 @@ impl Default for Log {
Self {
session_id: String::default(),
time: String::default(),
- level: LogLevel::INFO, // Default log level
+ level: LogLevel::INFO, // Default log level
component: String::default(),
description: String::default(),
- format: LogFormat::CLF, // Default log format
+ format: LogFormat::CLF, // Default log format
}
}
}
@@ -225,4 +240,4 @@ mod tests {
LogFormat::CLF
);
}
-}
\ No newline at end of file
+}
diff --git a/src/macros.rs b/src/macros.rs
index 5413a030..1e1a5032 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -522,27 +522,101 @@ macro_rules! macro_set_rss_data_fields {
};
}
+/// Custom logging macro for various log levels and formats.
+///
+/// # Parameters
+///
+/// * `$level`: The log level of the message.
+/// * `$component`: The component where the log is coming from.
+/// * `$description`: A description of the log message.
+/// * `$format`: The format of the log message.
+///
#[macro_export]
-/// # `macro_log_info` Macro
macro_rules! macro_log_info {
- ($level:expr, $component:expr, $description:expr, $format:expr) => {
- {
- use $crate::loggers::{Log, LogLevel, LogFormat};
-
- extern crate dtt;
- use dtt::DateTime;
- // Get the current date and time in ISO 8601 format.
- let date = DateTime::new();
- let iso = date.iso_8601;
-
- extern crate vrd;
- use vrd::Random;
- // Create a new random number generator
- let mut rng = Random::default();
- let session_id = rng.rand().to_string();
-
- let log = Log::new(&session_id, &iso, $level, $component, $description, $format);
- let _ = log.log();
- }
- };
+ ($level:expr, $component:expr, $description:expr, $format:expr) => {{
+ use dtt::DateTime;
+ use vrd::Random;
+ use $crate::loggers::{Log, LogFormat, LogLevel};
+
+ // Get the current date and time in ISO 8601 format.
+ let date = DateTime::new();
+ let iso = date.iso_8601;
+
+ // Create a new random number generator
+ let mut rng = Random::default();
+ let session_id = rng.rand().to_string();
+
+ let log = Log::new(
+ &session_id,
+ &iso,
+ $level,
+ $component,
+ $description,
+ $format,
+ );
+ let _ = log.log();
+ log // Return the Log instance
+ }};
+}
+
+/// Macros related to executing shell commands.
+///
+/// Executes a shell command, logs the start and completion of the operation, and handles any errors that occur.
+///
+/// # Parameters
+///
+/// * `$command`: The shell command to execute.
+/// * `$package`: The name of the package the command is being run on.
+/// * `$operation`: A description of the operation being performed.
+/// * `$start_message`: The log message to be displayed at the start of the operation.
+/// * `$complete_message`: The log message to be displayed upon successful completion of the operation.
+/// * `$error_message`: The log message to be displayed in case of an error.
+///
+/// # Returns
+///
+/// Returns a `Result<(), anyhow::Error>` indicating the success or failure of the operation.
+///
+#[macro_export]
+macro_rules! macro_execute_and_log {
+ ($command:expr, $package:expr, $operation:expr, $start_message:expr, $complete_message:expr, $error_message:expr) => {{
+ use anyhow::{Context, Result as AnyResult};
+ use $crate::loggers::{LogFormat, LogLevel};
+ use $crate::macro_log_info;
+
+ macro_log_info!(
+ LogLevel::INFO,
+ $operation,
+ $start_message,
+ LogFormat::CLF
+ );
+
+ $command
+ .run()
+ .map(|_| ())
+ .map_err(|err| {
+ macro_log_info!(
+ LogLevel::ERROR,
+ $operation,
+ $error_message,
+ LogFormat::CLF
+ );
+ err
+ })
+ .with_context(|| {
+ format!(
+ "Failed to execute '{}' for {} on package '{}'",
+ stringify!($command),
+ $operation,
+ $package
+ )
+ })?;
+
+ macro_log_info!(
+ LogLevel::INFO,
+ $operation,
+ $complete_message,
+ LogFormat::CLF
+ );
+ Ok(())
+ }};
}
\ No newline at end of file
diff --git a/src/term/cli.rs b/src/term/cli.rs
index 34d45327..c6fb05e6 100644
--- a/src/term/cli.rs
+++ b/src/term/cli.rs
@@ -44,7 +44,7 @@ pub fn build() -> Result {
.author("Sebastien Rousseau")
.about("")
.bin_name("ssg")
- .version("0.0.19")
+ .version("0.0.20")
.arg(
Arg::new("new")
.help("Create a new project.")
diff --git a/tests/test_loggers.rs b/tests/test_loggers.rs
new file mode 100644
index 00000000..bfb6b3db
--- /dev/null
+++ b/tests/test_loggers.rs
@@ -0,0 +1,129 @@
+#[cfg(test)]
+mod tests {
+
+ fn test_macro_log(
+ level: LogLevel,
+ component: &str,
+ description: &str,
+ format: LogFormat,
+ ) {
+ let log =
+ macro_log_info!(level, component, description, format);
+ assert_eq!(log.level, level);
+ assert_eq!(log.component, component);
+ assert_eq!(log.description, description);
+ assert_eq!(log.format, format);
+ }
+
+ #[test]
+ fn test_macros() {
+ test_macro_log(
+ LogLevel::ALL,
+ "component",
+ "description",
+ LogFormat::CLF,
+ );
+ test_macro_log(
+ LogLevel::DEBUG,
+ "component",
+ "description",
+ LogFormat::CLF,
+ );
+ test_macro_log(
+ LogLevel::DISABLED,
+ "component",
+ "description",
+ LogFormat::CLF,
+ );
+ test_macro_log(
+ LogLevel::ERROR,
+ "component",
+ "description",
+ LogFormat::CLF,
+ );
+ test_macro_log(
+ LogLevel::FATAL,
+ "component",
+ "description",
+ LogFormat::CLF,
+ );
+ test_macro_log(
+ LogLevel::INFO,
+ "component",
+ "description",
+ LogFormat::CLF,
+ );
+ test_macro_log(
+ LogLevel::NONE,
+ "component",
+ "description",
+ LogFormat::CLF,
+ );
+ test_macro_log(
+ LogLevel::TRACE,
+ "component",
+ "description",
+ LogFormat::CLF,
+ );
+ test_macro_log(
+ LogLevel::VERBOSE,
+ "component",
+ "description",
+ LogFormat::CLF,
+ );
+ test_macro_log(
+ LogLevel::WARNING,
+ "component",
+ "description",
+ LogFormat::CLF,
+ );
+ }
+
+ use ssg::{
+ loggers::{Log, LogFormat, LogLevel},
+ macro_log_info,
+ };
+
+ #[test]
+ fn test_log_level_display() {
+ let level = LogLevel::INFO;
+ assert_eq!(format!("{level}"), "INFO");
+ }
+
+ #[test]
+ fn test_log_format_display() {
+ let format = LogFormat::JSON;
+ assert_eq!(format!("{format}"), "JSON\n");
+ }
+
+ #[test]
+ fn test_log_new() {
+ let log = Log::new(
+ "session123",
+ "2023-02-28T12:34:56Z",
+ LogLevel::WARNING,
+ "auth",
+ "Invalid credentials",
+ LogFormat::CLF,
+ );
+
+ assert_eq!(log.session_id, "session123");
+ assert_eq!(log.time, "2023-02-28T12:34:56Z");
+ assert_eq!(log.level, LogLevel::WARNING);
+ assert_eq!(log.component, "auth");
+ assert_eq!(log.description, "Invalid credentials");
+ assert_eq!(log.format, LogFormat::CLF);
+ }
+
+ #[test]
+ fn test_log_default() {
+ let log = Log::default();
+
+ assert!(log.session_id.is_empty());
+ assert!(log.time.is_empty());
+ assert_eq!(log.level, LogLevel::INFO);
+ assert!(log.component.is_empty());
+ assert!(log.description.is_empty());
+ assert_eq!(log.format, LogFormat::CLF);
+ }
+}
\ No newline at end of file