Log
由construct_runtime
宏定义。以下是一些相关代码:
construct_runtime
宏:
https://github.com/paritytech/substrate/blob/950e90e75dc7d16dcf99972fcc733945a832dc3e/srml/support/src/runtime.rs#L79
macro_rules! construct_runtime {
(
pub enum $runtime:ident with Log ($log_internal:ident: DigestItem<$( $log_genarg:ty ),+>)
where
Block = $block:ident,
NodeBlock = $node_block:ty,
UncheckedExtrinsic = $uncheckedextrinsic:ident
{
$( $rest:tt )*
}
)
打电话__decl_outer_log
https://github.com/paritytech/substrate/blob/950e90e75dc7d16dcf99972fcc733945a832dc3e/srml/support/src/runtime.rs#L267
$crate::__decl_outer_log!(
$runtime;
$log_internal < $( $log_genarg ),* >;
{};
$(
$name: $module:: $( < $module_instance >:: )? { $( $modules $( ( $( $modules_args )* ) )* )* }
)*
);
__decl_outer_log
宏
https://github.com/paritytech/substrate/blob/950e90e75dc7d16dcf99972fcc733945a832dc3e/srml/support/src/runtime.rs#L706
macro_rules! __decl_outer_log {
(
$runtime:ident;
$log_internal:ident <$( $log_genarg:ty ),+>;
{ $( $parsed:tt )* };
$name:ident: $module:ident:: $(<$module_instance:ident>::)? {
Log ( $( $args:ident )* ) $( $modules:ident $( ( $( $modules_args:ident )* ) )* )*
}
$( $rest:tt )*
) => {
打电话impl_outer_log
https://github.com/paritytech/substrate/blob/950e90e75dc7d16dcf99972fcc733945a832dc3e/srml/support/src/runtime.rs#L763
(
$runtime:ident;
$log_internal:ident <$( $log_genarg:ty ),+>;
{ $(
$parsed_modules:ident $(< $parsed_instance:ident >)? ( $( $parsed_args:ident )* )
)* };
) => {
$crate::paste::item! {
$crate::runtime_primitives::impl_outer_log!(
pub enum Log($log_internal: DigestItem<$( $log_genarg ),*>) for $runtime {
$( [< $parsed_modules $(_ $parsed_instance)? >] $(< $parsed_modules::$parsed_instance >)? ( $( $parsed_args ),* ) ),*
}
);
}
};
impl_outer_log
宏:
https ://github.com/paritytech/substrate/blob/950e90e75dc7d16dcf99972fcc733945a832dc3e/core/sr-primitives/src/lib.rs#L630
macro_rules! impl_outer_log {
(
$(#[$attr:meta])*
pub enum $name:ident ($internal:ident: DigestItem<$( $genarg:ty ),*>) for $trait:ident {
$( $module:ident $(<$instance:path>)? ( $( $sitem:ident ),* ) ),*
}
)
它实际上声明并实现了Log
结构
您应该能够cargo expand
在运行时 crate 时看到结果。