aboutsummaryrefslogtreecommitdiff
path: root/games/rstnode/rst-server/src/log.rs
blob: 676395134a5908e7251944954ddaedd31bed0f99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! 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("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)
    })
}