0
0
Fork 0
mirror of https://git.verdigado.com/NB-Public/simple-wkd.git synced 2024-10-30 03:05:51 +01:00

Add macro for easier logging

This commit is contained in:
Delta1925 2023-04-18 22:10:23 +02:00
parent 2ce66b9ba0
commit c67cfc68a2
No known key found for this signature in database
GPG key ID: 1C21ACE44193CB25
2 changed files with 26 additions and 0 deletions

View file

@ -5,6 +5,31 @@ use thiserror::Error as DeriveError;
use crate::utils::return_outcome;
#[macro_export]
macro_rules! log_err {
($var: expr, $level: ident) => {{
let test = $var;
if test.is_err() {
$level!("{} {}", $crate::settings::ERROR_TEXT, test.as_ref().unwrap_err());
test
} else {
test
}
}};
($var: expr, $level: ident, $panic: expr) => {{
let test = $var;
if log_err!(test, $level).is_err() {
if $panic == true {
panic!("{} {}", $crate::settings::ERROR_TEXT, test.unwrap_err());
} else {
test
}
} else {
$var
}
}};
}
#[derive(Debug, DeriveError)]
pub enum SpecialErrors {
#[error("Could not find any primay user email in the keyblock!")]

View file

@ -85,6 +85,7 @@ fn get_mailer() -> SmtpTransport {
mailer
}
pub const ERROR_TEXT: &str = "An error occoured:";
pub const POLICY: &StandardPolicy = &StandardPolicy::new();
pub const ROOT_FOLDER: &str = "data";
pub static SETTINGS: Lazy<Settings> = Lazy::new(get_settings);