use wasm_bindgen::JsValue;
#[macro_export]
macro_rules! log {
($($t:tt)*) => ($crate::logging::console_log(&format_args!($($t)*).to_string()))
}
#[macro_export]
macro_rules! warn {
($($t:tt)*) => ($crate::logging::console_warn(&format_args!($($t)*).to_string()))
}
#[macro_export]
macro_rules! error {
($($t:tt)*) => ($crate::logging::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)*)
}
}
}
}
const fn log_to_stdout() -> bool {
cfg!(not(all(
target_arch = "wasm32",
not(any(target_os = "emscripten", target_os = "wasi"))
)))
}
pub fn console_log(s: &str) {
#[allow(clippy::print_stdout)]
if log_to_stdout() {
println!("{s}");
} else {
web_sys::console::log_1(&JsValue::from_str(s));
}
}
pub fn console_warn(s: &str) {
if log_to_stdout() {
eprintln!("{s}");
} else {
web_sys::console::warn_1(&JsValue::from_str(s));
}
}
#[inline(always)]
pub fn console_error(s: &str) {
if log_to_stdout() {
eprintln!("{s}");
} else {
web_sys::console::error_1(&JsValue::from_str(s));
}
}
#[inline(always)]
pub fn console_debug_warn(s: &str) {
#[cfg(debug_assertions)]
{
if log_to_stdout() {
eprintln!("{s}");
} else {
web_sys::console::warn_1(&JsValue::from_str(s));
}
}
#[cfg(not(debug_assertions))]
{
let _ = s;
}
}