referrerpolicy=no-referrer-when-downgrade

sc_transaction_pool/common/
tracing_log_xt.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
5
6// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
10
11// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19//! Utility for logging transaction collections with tracing crate.
20
21/// Logs every transaction from given `tx_collection` with given level.
22macro_rules! log_xt {
23    (data: hash, target: $target:expr, $level:expr, $tx_collection:expr, $text_with_format:expr) => {
24        for tx_hash in $tx_collection {
25            tracing::event!(
26                target: $target,
27                $level,
28                ?tx_hash,
29                $text_with_format,
30            );
31        }
32    };
33    (data: hash, target: $target:expr, $level:expr, $tx_collection:expr, $text_with_format:expr, $($arg:expr),*) => {
34        for tx_hash in $tx_collection {
35            tracing::event!(
36                target: $target,
37                $level,
38                ?tx_hash,
39                $text_with_format,
40                $($arg),*
41            );
42        }
43    };
44    (data: tuple, target: $target:expr, $level:expr, $tx_collection:expr, $text_with_format:expr) => {
45        for (tx_hash, arg) in $tx_collection {
46            tracing::event!(
47                target: $target,
48                $level,
49                ?tx_hash,
50                $text_with_format,
51                arg
52            );
53        }
54    };
55}
56macro_rules! log_xt_debug {
57    (data: $datatype:ident, target: $target:expr, $($arg:tt)+) => {
58        $crate::common::tracing_log_xt::log_xt!(data: $datatype, target: $target, tracing::Level::DEBUG, $($arg)+);
59    };
60    (target: $target:expr, $tx_collection:expr, $text_with_format:expr) => {
61        $crate::common::tracing_log_xt::log_xt!(data: hash, target: $target, tracing::Level::DEBUG, $tx_collection, $text_with_format);
62    };
63    (target: $target:expr, $tx_collection:expr, $text_with_format:expr, $($arg:expr)*) => {
64        $crate::common::tracing_log_xt::log_xt!(data: hash, target: $target, tracing::Level::DEBUG, $tx_collection, $text_with_format, $($arg)*);
65    };
66}
67
68macro_rules! log_xt_trace {
69    (data: $datatype:ident, target: $target:expr, $($arg:tt)+) => {
70        $crate::common::tracing_log_xt::log_xt!(data: $datatype, target: $target, tracing::Level::TRACE, $($arg)+);
71    };
72    (target: $target:expr, $tx_collection:expr, $text_with_format:expr) => {
73        $crate::common::tracing_log_xt::log_xt!(data: hash, target: $target, tracing::Level::TRACE, $tx_collection, $text_with_format);
74    };
75    (target: $target:expr, $tx_collection:expr, $text_with_format:expr, $($arg:expr)*) => {
76        $crate::common::tracing_log_xt::log_xt!(data: hash, target: $target, tracing::Level::TRACE, $tx_collection, $text_with_format, $($arg)*);
77    };
78}
79
80pub(crate) use log_xt;
81pub(crate) use log_xt_debug;
82pub(crate) use log_xt_trace;