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
58
59
60
61
62
63
64
65
66
67
68
69
70
use wasm_bindgen::JsValue;

use crate::is_server;

#[macro_export]
macro_rules! log {
    ($($t:tt)*) => ($crate::console_log(&format_args!($($t)*).to_string()))
}

#[macro_export]
macro_rules! warn {
    ($($t:tt)*) => ($crate::console_warn(&format_args!($($t)*).to_string()))
}

#[macro_export]
macro_rules! error {
    ($($t:tt)*) => ($crate::console_error(&format_args!($($t)*).to_string()))
}

#[macro_export]
macro_rules! debug_warn {
    ($($x:tt)*) => {
        {
            #[cfg(debug_assertions)]
            {
                $crate::warn!($($x)*)
            }
            #[cfg(not(debug_assertions))]
            {
                ($($x)*)
            }
        }
    }
}

pub fn console_log(s: &str) {
    if is_server!() {
        println!("{}", s);
    } else {
        web_sys::console::log_1(&JsValue::from_str(s));
    }
}

pub fn console_warn(s: &str) {
    if is_server!() {
        eprintln!("{}", s);
    } else {
        web_sys::console::warn_1(&JsValue::from_str(s));
    }
}

pub fn console_error(s: &str) {
    if is_server!() {
        eprintln!("{}", s);
    } else {
        web_sys::console::warn_1(&JsValue::from_str(s));
    }
}

#[cfg(debug_assertions)]
pub fn console_debug_warn(s: &str) {
    if is_server!() {
        eprintln!("{}", s);
    } else {
        web_sys::console::warn_1(&JsValue::from_str(s));
    }
}

#[cfg(not(debug_assertions))]
pub fn console_debug_warn(_s: &str) {}