diff --git a/src/echo/display.rs b/src/echo/display.rs deleted file mode 100644 index 6bf6de5..0000000 --- a/src/echo/display.rs +++ /dev/null @@ -1,31 +0,0 @@ -#[allow(dead_code)] -pub struct Format { - pub bold: &'static str, - pub underline: &'static str, - pub italic: &'static str, -} - -pub struct Colors { - pub green: &'static str, - pub yellow: &'static str, - pub red: &'static str, - pub end: &'static str, - pub light_green: &'static str, -} - -#[allow(dead_code)] -pub fn format() -> Format { - let bold = "\x1B[1m"; - let underline = "\x1B[4m"; - let italic = "\x1B[3m"; - Format { bold, underline, italic } -} - -pub fn colors() -> Colors { - let green = "\x1B[92m"; - let yellow = "\x1B[93m"; - let red = "\x1B[91m"; - let end = "\x1B[0m"; - let light_green = "\x1B[32m"; - Colors { green, yellow, red, end, light_green } -} diff --git a/src/echo/functions.rs b/src/echo/functions.rs deleted file mode 100644 index 26565f4..0000000 --- a/src/echo/functions.rs +++ /dev/null @@ -1,40 +0,0 @@ -use chrono::{Local, Utc}; -use crate::echo::display; - -fn get_time(utc: bool) -> String { - if utc { - Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true) - } else { - Local::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true) - } -} - -#[allow(dead_code)] -pub fn debug_func(msg: &str, utc: bool) { - let colors = display::colors(); - println!("[{} {}DEBUG{} {}] {}", get_time(utc), colors.light_green, colors.end, env!("CARGO_CRATE_NAME"), msg) -} - -pub fn info_func(msg: &str, utc: bool) { - let colors = display::colors(); - println!("[{} {}INFO{} {}] {}", get_time(utc), colors.green, colors.end, env!("CARGO_CRATE_NAME"), msg) -} - -#[allow(dead_code)] -pub fn warn_func(msg: &str, utc: bool) { - let colors = display::colors(); - println!("[{} {}WARN{} {}] {}", get_time(utc), colors.yellow, colors.end, env!("CARGO_CRATE_NAME"), msg) -} - -#[allow(dead_code)] -pub fn error_func(msg: &str, utc: bool) { - let colors = display::colors(); - println!("[{} {}ERROR{} {}] {}", get_time(utc), colors.red, colors.end, env!("CARGO_CRATE_NAME"), msg) -} - -#[allow(dead_code)] -pub fn critical_func(msg: &str, utc: bool) { - let colors = display::colors(); - let format = display::format(); - println!("[{} {}{}CRITICAL{} {}] {}", get_time(utc), format.bold, colors.red, colors.end, env!("CARGO_CRATE_NAME"), msg) -} diff --git a/src/echo/macros.rs b/src/echo/macros.rs deleted file mode 100644 index c418275..0000000 --- a/src/echo/macros.rs +++ /dev/null @@ -1,49 +0,0 @@ -#[macro_export] -macro_rules! debug { - ($msg:expr) => { - $crate::echo::functions::debug_func($msg, false) - }; - ($msg:expr, $flag:expr) => { - $crate::echo::functions::debug_func($msg, $flag) - }; -} - -#[macro_export] -macro_rules! info { - ($msg:expr) => { - $crate::echo::functions::info_func($msg, false) - }; - ($msg:expr, $flag:expr) => { - $crate::echo::functions::info_func($msg, $flag) - }; -} - -#[macro_export] -macro_rules! warn { - ($msg:expr) => { - $crate::echo::functions::warn_func($msg, false) - }; - ($msg:expr, $flag:expr) => { - $crate::echo::functions::warn_func($msg, $flag) - }; -} - -#[macro_export] -macro_rules! error { - ($msg:expr) => { - $crate::echo::functions::error_func($msg, false) - }; - ($msg:expr, $flag:expr) => { - $crate::echo::functions::error_func($msg, $flag) - }; -} - -#[macro_export] -macro_rules! critical { - ($msg:expr) => { - $crate::echo::functions::critical_func($msg, false) - }; - ($msg:expr, $flag:expr) => { - $crate::echo::functions::critical_func($msg, $flag) - }; -} diff --git a/src/echo/mod.rs b/src/echo/mod.rs deleted file mode 100644 index 8168cf7..0000000 --- a/src/echo/mod.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub mod functions; - -#[macro_use] -pub mod macros; -pub mod display; diff --git a/src/lib.rs b/src/lib.rs index f7c7b9f..7c0a873 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -17,7 +17,6 @@ mod routes; mod squire; /// Module to load all the templates for the UI. mod templates; -mod echo; /// Contains entrypoint and initializer settings to trigger the asynchronous `HTTPServer` /// diff --git a/src/squire/settings.rs b/src/squire/settings.rs index fc56b2e..d00c563 100644 --- a/src/squire/settings.rs +++ b/src/squire/settings.rs @@ -42,7 +42,7 @@ pub struct Config { pub fn default_debug() -> bool { false } /// Returns the default value for utc_logging -pub fn default_utc_logging() -> bool { false } +pub fn default_utc_logging() -> bool { true } /// Returns the default value for ssl files pub fn default_ssl() -> path::PathBuf { path::PathBuf::new() } diff --git a/src/squire/startup.rs b/src/squire/startup.rs index afa7f69..00c1eaf 100644 --- a/src/squire/startup.rs +++ b/src/squire/startup.rs @@ -1,11 +1,12 @@ use std; use std::ffi::OsStr; use std::io::Write; -use chrono::{DateTime, Local}; + +use chrono::{DateTime, Local, Utc}; use walkdir::WalkDir; +use crate::{constant, squire}; use crate::constant::Cargo; -use crate::{constant, info, squire}; use crate::squire::settings; /// Initializes the logger based on the provided debug flag and cargo information. @@ -35,8 +36,8 @@ pub fn init_logger(debug: bool, utc: bool, crate_name: &String) { let local_time: DateTime = Local::now(); writeln!( buf, - "[{} {}] [{}] - {}", - local_time.format("%Y-%m-%d %H:%M:%S"), + "[{} {} {}] - {}", + local_time.format("%Y-%m-%dT%H:%M:%SZ"), record.level(), record.target(), record.args() @@ -216,7 +217,15 @@ fn load_env_vars() -> settings::Config { } } -fn validate_dir_structure(config: &settings::Config) { +fn get_time(utc: bool) -> String { + if utc { + Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true) + } else { + Local::now().to_rfc3339_opts(chrono::SecondsFormat::Secs, true) + } +} + +fn validate_dir_structure(config: &settings::Config, cargo: &Cargo) { let source = &config.media_source.to_string_lossy().to_string(); let mut errors = String::new(); for entry in WalkDir::new(&config.media_source).into_iter().filter_map(|e| e.ok()) { @@ -249,7 +258,9 @@ fn validate_dir_structure(config: &settings::Config) { let secure_path = &config.media_source.join(format!("{}_{}", &username, constant::SECURE_INDEX)); if !secure_path.exists() { match std::fs::create_dir(&secure_path) { - Ok(_) => info!(&format!("'{}' has been created", &secure_path.to_str().unwrap()).as_str()), + Ok(_) => println!("[{}\x1b[32m INFO\x1b[0m {}] '{}' has been created", + get_time(config.utc_logging), cargo.crate_name, + &secure_path.to_str().unwrap()), Err(err) => panic!("{}", err) } } @@ -264,7 +275,7 @@ fn validate_dir_structure(config: &settings::Config) { /// # Returns /// /// Returns the `Config` struct containing the required parameters. -fn validate_vars() -> settings::Config { +fn validate_vars(cargo: &Cargo) -> settings::Config { let config = load_env_vars(); let mut errors = "".to_owned(); if !config.media_source.exists() || !config.media_source.is_dir() { @@ -293,7 +304,7 @@ fn validate_vars() -> settings::Config { if !errors.is_empty() { panic!("{}", errors); } - validate_dir_structure(&config); + validate_dir_structure(&config, &cargo); config } @@ -313,5 +324,5 @@ pub fn get_config(cargo: &Cargo) -> std::sync::Arc { .unwrap_or_default() .join(env_file); let _ = dotenv::from_path(env_file_path.as_path()); - std::sync::Arc::new(validate_vars()) + std::sync::Arc::new(validate_vars(cargo)) }