diff options
Diffstat (limited to 'games/rstnode/log.rs')
-rw-r--r-- | games/rstnode/log.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/games/rstnode/log.rs b/games/rstnode/log.rs new file mode 100644 index 000000000000..6462413952e1 --- /dev/null +++ b/games/rstnode/log.rs @@ -0,0 +1,61 @@ +//! Logging specifics + +const BANNER: &'static str = " +██████╗ ███████╗████████╗ ███╗ ██╗ ██████╗ ██████╗ ███████╗ +██╔══██╗██╔════╝╚══██╔══╝ ████╗ ██║██╔═══██╗██╔══██╗██╔════╝ +██████╔╝███████╗ ██║ ██╔██╗ ██║██║ ██║██║ ██║█████╗ +██╔══██╗╚════██║ ██║ ██║╚██╗██║██║ ██║██║ ██║██╔══╝ +██║ ██║███████║ ██║ ██║ ╚████║╚██████╔╝██████╔╝███████╗ +╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝ ╚═══╝ ╚═════╝ ╚═════╝ ╚══════╝"; + +use systemstat::{Platform, System}; +use tracing_subscriber::{filter::LevelFilter, fmt, EnvFilter}; + +#[cfg(not(target_os = "windows"))] +const PLATFORM_DISCLAIMER: &'static str = "Platform: Unspecified *nix-like"; +#[cfg(target_os = "windows")] +static PLATFORM_DISCLAIMER: &'static str = + "WARNING: Windows server hosts are not officially supported!"; + +pub(crate) fn initialise() { + let filter = EnvFilter::try_from_env("RST_LOG") + .unwrap_or_default() + .add_directive(LevelFilter::DEBUG.into()) + .add_directive("async_std=error".parse().unwrap()) + .add_directive("gfx_device_gl=error".parse().unwrap()) + .add_directive("ggez=error".parse().unwrap()) + .add_directive("selectors=error".parse().unwrap()) + .add_directive("gilrs=error".parse().unwrap()) + .add_directive("mio=error".parse().unwrap()); + + // Initialise the logger + fmt().with_env_filter(filter).init(); + info!("Initialising..."); + info!("{}", BANNER); + info!("{}", PLATFORM_DISCLAIMER); + info!("Available cores: {}", num_cpus::get()); + info!("Available RAM: {}", mem()); + info!("Version: {}", crate::constants::VERSION); +} + +fn mem() -> String { + let sys = System::new(); + let mem = sys.memory().unwrap(); + format!( + "{} / {}", + mem.free.to_string_as(true), + mem.total.to_string_as(true) + ) +} + +#[macro_export] +macro_rules! fatal { + () => { + error!("Unknown failure!"); + std::process::exit(2) + }; + ($($arg:tt)*) => ({ + error!($($arg)*); + std::process::exit(2) + }) +} |