rss2email_lib/logger/mod.rs
1//! This file contains wrapper macros for the `env_logger` crate.
2//! I specifically wanted to wrap around `warn` as I wanted all warnings
3//! to panic if they occurred in the Github Actions workflow.
4
5/// Calls [`log::info!`].
6#[macro_export]
7macro_rules! info {
8 ( $($arg:tt)+ ) => {{
9 log::info!($($arg)+)
10 }}
11}
12
13#[allow(clippy::too_long_first_doc_paragraph)]
14/// Calls [`log::warn!`] if executed outside of Github Actions. If it is executed inside
15/// of GA, it instead panics. This is done to make sure that no warnings are missed during a
16/// workflow run. GA sets an environment variable `CI=TRUE` which is how I determine if this
17/// should panic or not.
18#[macro_export]
19macro_rules! warn {
20 ( $($arg:tt)+ ) => {{
21 lazy_static::lazy_static!{
22 static ref IS_CI: bool = std::env::var("CI").ok().map_or_else(|| "FALSE".to_owned(), |x| x.to_uppercase()) == "TRUE";
23 }
24
25 if *IS_CI {
26 panic!($($arg)+)
27 } else {
28 log::warn!($($arg)+)
29 }
30 }}
31}
32
33/// Calls [`log::error!`].
34#[macro_export]
35macro_rules! error {
36 ( $($arg:tt)+ ) => {{
37 log::error!($($arg)+)
38 }}
39}