|
| 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. |
| 22 | +macro_rules! log_xt { |
| 23 | + (data: hash, target: $target:expr, $level:expr, $tx_collection:expr, $text_with_format:expr) => { |
| 24 | + for tx in $tx_collection { |
| 25 | + tracing::event!( |
| 26 | + $level, |
| 27 | + target = $target, |
| 28 | + tx_hash = format!("{:?}", tx), |
| 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 in $tx_collection { |
| 35 | + tracing::event!( |
| 36 | + $level, |
| 37 | + target = $target, |
| 38 | + tx_hash = format!("{:?}", tx), |
| 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 in $tx_collection { |
| 46 | + tracing::event!( |
| 47 | + $level, |
| 48 | + target = $target, |
| 49 | + tx_hash = format!("{:?}", tx.0), |
| 50 | + $text_with_format, |
| 51 | + tx.1 |
| 52 | + ); |
| 53 | + } |
| 54 | + }; |
| 55 | +} |
| 56 | +macro_rules! log_xt_trace { |
| 57 | + (data: $datatype:ident, target: $target:expr, $($arg:tt)+) => { |
| 58 | + $crate::common::tracing_log_xt::log_xt!(data: $datatype, target: $target, tracing::Level::TRACE, $($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::TRACE, $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::TRACE, $tx_collection, $text_with_format, $($arg)*); |
| 65 | + }; |
| 66 | +} |
| 67 | + |
| 68 | +pub(crate) use log_xt; |
| 69 | +pub(crate) use log_xt_trace; |
0 commit comments