rog/
lib.rs

1//! A Rust logger. Provides macro `debugln!()` and `println!()`.
2//!
3//! # Example
4//! ```edition2021
5//! rog::reg("main");
6//! rog::debugln!("debug");
7//! rog::println!("print");
8//! ```
9
10use std::collections::HashSet;
11pub use std::println;
12
13static mut C: Option<HashSet<&'static str>> = None;
14
15/// Returns a hashset indicating which modules have been registered.
16pub fn cfg() -> &'static mut HashSet<&'static str> {
17    unsafe { C.get_or_insert(HashSet::new()) }
18}
19
20/// Debugs to the standard output, with a newline.
21#[macro_export]
22macro_rules! debugln {
23    ($($arg:tt)*) => ({
24        if rog::cfg().contains(module_path!()) {
25            print!($($arg)*);
26            print!("\n");
27        }
28    })
29}
30
31/// Register a series of module names, the logs in this module will be printed.
32pub fn reg(module: &'static str) {
33    let c = cfg();
34    c.insert(module);
35}