Skip to content
Snippets Groups Projects
Commit 545d223b authored by cmd[bot]'s avatar cmd[bot]
Browse files

Update from seemantaggarwal running command 'fmt'

parent 38d5c3c3
No related merge requests found
Pipeline #518045 waiting for manual action with stages
in 1 hour, 26 minutes, and 47 seconds
......@@ -104,45 +104,45 @@ mod utils;
#[proc_macro_attribute]
pub fn prefix_logs_with(arg: TokenStream, item: TokenStream) -> TokenStream {
// Ensure an argument was provided.
if arg.is_empty() {
return Error::new(
proc_macro2::Span::call_site(),
"missing argument: prefix. Example: prefix_logs_with(\"Relaychain\")",
)
.to_compile_error()
.into();
}
// Ensure an argument was provided.
if arg.is_empty() {
return Error::new(
proc_macro2::Span::call_site(),
"missing argument: prefix. Example: prefix_logs_with(\"Relaychain\")",
)
.to_compile_error()
.into();
}
let prefix_expr = syn::parse_macro_input!(arg as Expr);
let item_fn = syn::parse_macro_input!(item as ItemFn);
let prefix_expr = syn::parse_macro_input!(arg as Expr);
let item_fn = syn::parse_macro_input!(item as ItemFn);
// Resolve the proper sc_tracing path.
let resolved_crate = match utils::resolve_sc_tracing() {
Ok(path) => path,
Err(err) => return err.to_compile_error().into(),
};
// Resolve the proper sc_tracing path.
let resolved_crate = match utils::resolve_sc_tracing() {
Ok(path) => path,
Err(err) => return err.to_compile_error().into(),
};
let syn::ItemFn { attrs, vis, sig, block } = item_fn;
let syn::ItemFn { attrs, vis, sig, block } = item_fn;
// Generate different output based on whether the function is async.
let output = if sig.asyncness.is_some() {
// Async branch: wrap the block in a closure that returns an async block.
quote! {
#(#attrs)*
#vis #sig {
#resolved_crate::logging::apply_prefix_async(#prefix_expr, || async { #block }).await
}
}
} else {
// Sync branch: call the synchronous logging helper.
quote! {
#(#attrs)*
#vis #sig {
#resolved_crate::logging::apply_prefix_sync(#prefix_expr, || { #block })
}
}
};
// Generate different output based on whether the function is async.
let output = if sig.asyncness.is_some() {
// Async branch: wrap the block in a closure that returns an async block.
quote! {
#(#attrs)*
#vis #sig {
#resolved_crate::logging::apply_prefix_async(#prefix_expr, || async { #block }).await
}
}
} else {
// Sync branch: call the synchronous logging helper.
quote! {
#(#attrs)*
#vis #sig {
#resolved_crate::logging::apply_prefix_sync(#prefix_expr, || { #block })
}
}
};
output.into()
}
\ No newline at end of file
output.into()
}
......@@ -6,15 +6,13 @@ use syn::{Path, Result};
/// - If `polkadot-sdk` is in scope, returns a Path corresponding to `polkadot_sdk::sc_tracing`
/// - Otherwise, falls back to `sc_tracing`
pub fn resolve_sc_tracing() -> Result<Path> {
match crate_name("polkadot-sdk") {
Ok(FoundCrate::Itself) => syn::parse_str("polkadot_sdk::sc_tracing"),
Ok(FoundCrate::Name(sdk_name)) => syn::parse_str(&format!("{}::sc_tracing", sdk_name)),
Err(_) => {
match crate_name("sc-tracing") {
Ok(FoundCrate::Itself) => syn::parse_str("sc_tracing"),
Ok(FoundCrate::Name(name)) => syn::parse_str(&name),
Err(e) => Err(syn::Error::new(Span::call_site(), e)),
}
}
}
match crate_name("polkadot-sdk") {
Ok(FoundCrate::Itself) => syn::parse_str("polkadot_sdk::sc_tracing"),
Ok(FoundCrate::Name(sdk_name)) => syn::parse_str(&format!("{}::sc_tracing", sdk_name)),
Err(_) => match crate_name("sc-tracing") {
Ok(FoundCrate::Itself) => syn::parse_str("sc_tracing"),
Ok(FoundCrate::Name(name)) => syn::parse_str(&name),
Err(e) => Err(syn::Error::new(Span::call_site(), e)),
},
}
}
......@@ -96,7 +96,6 @@ where
f().await
}
/// Convert a `Option<LevelFilter>` to a [`log::LevelFilter`].
///
/// `None` is interpreted as `Info`.
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment