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 occured 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/// Calls [`log::warn!`] if executed outside of Github Actions. If it is executed inside
14/// of GA, it instead panics. This is done to make sure that no warnings are missed during a
15/// workflow run. GA sets an environment variable `CI=TRUE` which is how I determine if this
16/// should panic or not.
17#[macro_export]
18macro_rules! warn {
19  ( $($arg:tt)+ ) => {{
20    lazy_static::lazy_static!{
21      static ref IS_CI: bool = std::env::var("CI").ok().map_or_else(|| "FALSE".to_owned(), |x| x.to_uppercase()) == "TRUE";
22    }
23
24    if *IS_CI {
25      panic!($($arg)+)
26    } else {
27      log::warn!($($arg)+)
28    }
29  }}
30}
31
32/// Calls [`log::error!`].
33#[macro_export]
34macro_rules! error {
35  ( $($arg:tt)+ ) => {{
36    log::error!($($arg)+)
37  }}
38}