dscale/helpers/logger.rs
1// DScale: deterministic distributed systems simulator
2// Copyright (C) 2026 Konstantin Shprenger
3
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16
17/// Logs at the given level, prefixed with simulation time and process pid.
18/// Controlled by the `RUST_LOG` environment variable.
19#[macro_export]
20macro_rules! dscale_log {
21 ($level:ident, $($arg:tt)+) => {
22 $crate::log::$level!("[Now: {}][P{}] {}", $crate::now(), $crate::pid(), format_args!($($arg)+));
23 }
24}
25
26/// Logs at **trace** level. See [`dscale_log`].
27#[macro_export]
28macro_rules! dscale_trace {
29 ($($arg:tt)+) => { $crate::dscale_log!(trace, $($arg)+); }
30}
31
32/// Logs at **debug** level. See [`dscale_log`].
33#[macro_export]
34macro_rules! dscale_debug {
35 ($($arg:tt)+) => { $crate::dscale_log!(debug, $($arg)+); }
36}
37
38/// Logs at **info** level. See [`dscale_log`].
39#[macro_export]
40macro_rules! dscale_info {
41 ($($arg:tt)+) => { $crate::dscale_log!(info, $($arg)+); }
42}
43
44/// Logs at **warn** level. See [`dscale_log`].
45#[macro_export]
46macro_rules! dscale_warn {
47 ($($arg:tt)+) => { $crate::dscale_log!(warn, $($arg)+); }
48}
49
50/// Logs at **error** level. See [`dscale_log`].
51#[macro_export]
52macro_rules! dscale_error {
53 ($($arg:tt)+) => { $crate::dscale_log!(error, $($arg)+); }
54}