My personal project and infrastructure archive
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
nomicon/games/rstnode/log.rs

61 lines
2.6 KiB

//! 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)
})
}