mango_core/
logging.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2//
3// Copyright (c) 2018-2023 Andre Richter <andre.o.richter@gmail.com>
4
5/// Prints an info, with a newline.
6#[macro_export]
7macro_rules! info {
8    ($string:expr) => ({
9        let timestamp = $crate::TIME.lock().get_uptime_or(0);
10
11        $crate::println!(
12            concat!("[  {:>3}.{:06}] ", $string, "\n"),
13            timestamp.as_secs(),
14            timestamp.subsec_micros(),
15        );
16    });
17    ($format_string:expr, $($arg:tt)*) => ({
18        let timestamp = $crate::TIME.lock().get_uptime_or(0);
19
20        $crate::println!(
21            concat!("[  {:>3}.{:06}] ", $format_string, "\n"),
22            timestamp.as_secs(),
23            timestamp.subsec_micros(),
24            $($arg)*
25        );
26    })
27}
28
29/// Prints a warning, with a newline.
30#[macro_export]
31macro_rules! warn {
32    ($string:expr) => ({
33        let timestamp = $crate::TIME.lock().get_uptime_or(0);
34
35        $crate::println!(
36            concat!("[W {:>3}.{:06}] ", $string),
37            timestamp.as_secs(),
38            timestamp.subsec_micros(),
39        );
40    });
41    ($format_string:expr, $($arg:tt)*) => ({
42        let timestamp = $crate::TIME.lock().get_uptime_or(0);
43
44        $crate::println!(
45            concat!("[W {:>3}.{:06}] ", $format_string),
46            timestamp.as_secs(),
47            timestamp.subsec_micros(),
48            $($arg)*
49        );
50    })
51}
52
53/// Debug print, with a newline.
54#[macro_export]
55macro_rules! debug {
56    ($string:expr) => ({
57        if cfg!(feature = "debug_prints") {
58            let timestamp = $crate::TIME.lock().get_uptime_or(0);
59
60            $crate::println!(
61                concat!("<[>D {:>3}.{:06}> ", $string, "\n"),
62                timestamp.as_secs(),
63                timestamp.subsec_micros(),
64            );
65        }
66    });
67    ($format_string:expr, $($arg:tt)*) => ({
68        if cfg!(feature = "debug_prints") {
69            let timestamp = $crate::TIME.lock().get_uptime_or(0);
70
71            $crate::println!(
72                concat!("<D {:>3}.{:06}> ", $format_string, "\n"),
73                timestamp.as_secs(),
74                timestamp.subsec_micros(),
75                $($arg)*
76            );
77        }
78    })
79}