tanoshi_util/
log.rs

1#[macro_export]
2macro_rules! debug {
3    ($($arg:tt)+) => {
4        let message = format!($($arg)+);
5        let message = format!("[{}] {}", std::module_path!(), message);
6        $crate::log::print_debug(message);
7    };
8}
9
10#[macro_export]
11macro_rules! error {
12    ($($arg:tt)+) => {
13        let message = format!($($arg)+);
14        let message = format!("[{}] {}", std::module_path!(), message);
15        $crate::log::print_error(message);
16    };
17}
18
19#[macro_export]
20macro_rules! info {
21    ($($arg:tt)+) => {
22        let message = format!($($arg)+);
23        let message = format!("[{}] {}", std::module_path!(), message);
24        $crate::log::print_info(message);
25    };
26}
27
28#[macro_export]
29macro_rules! trace {
30    ($($arg:tt)+) => {
31        let message = format!($($arg)+);
32        let message = format!("[{}] {}", std::module_path!(), message);
33        $crate::log::print_trace(message);
34    };
35}
36
37#[macro_export]
38macro_rules! warn {
39    ($($arg:tt)+) => {
40        let message = format!($($arg)+);
41        let message = format!("[{}] {}", std::module_path!(), message);
42        $crate::log::print_warn(message);
43    };
44}
45
46#[cfg(all(not(feature = "__test"), not(feature = "host")))]
47pub fn print_debug(message: String) {
48    crate::shim::write_err(message);
49    unsafe { host_debug() };
50}
51
52#[cfg(all(not(feature = "__test"), not(feature = "host")))]
53pub fn print_error(message: String) {
54    crate::shim::write_err(message);
55    unsafe { host_error() };
56}
57
58#[cfg(all(not(feature = "__test"), not(feature = "host")))]
59pub fn print_info(message: String) {
60    crate::shim::write_err(message);
61    unsafe { host_info() };
62}
63
64#[cfg(all(not(feature = "__test"), not(feature = "host")))]
65pub fn print_trace(message: String) {
66    crate::shim::write_err(message);
67    unsafe { host_trace() };
68}
69
70#[cfg(all(not(feature = "__test"), not(feature = "host")))]
71pub fn warn(message: String) {
72    crate::shim::write_err(message);
73    unsafe { host_warn() };
74}
75
76#[cfg(all(not(feature = "__test"), not(feature = "host")))]
77#[link(wasm_import_module = "tanoshi")]
78extern "C" {
79    fn host_debug();
80    fn host_error();
81    fn host_info();
82    fn host_trace();
83    fn host_warn();
84}
85
86#[cfg(any(feature = "__test", feature = "host"))]
87pub fn print_debug(message: String) {
88    log::debug!(target: "extension", "{}", message);
89}
90
91#[cfg(any(feature = "__test", feature = "host"))]
92pub fn print_error(message: String) {
93    log::error!(target: "extension", "{}", message);
94}
95
96#[cfg(any(feature = "__test", feature = "host"))]
97pub fn print_info(message: String) {
98    log::info!(target: "extension", "{}", message);
99}
100
101#[cfg(any(feature = "__test", feature = "host"))]
102pub fn print_trace(message: String) {
103    log::trace!(target: "extension", "{}", message);
104}
105
106#[cfg(any(feature = "__test", feature = "host"))]
107pub fn print_warn(message: String) {
108    log::warn!(target: "extension", "{}", message);
109}