Use codegen event target prefix 'rocket::codegen'.

This commit prefixes the target of all trace events emitted by codegen
with `rocket::codegen::{kind}::{module_path!()}`, where `kind` is the
kind of codegen item that was generated (i.e, `route`). This increases
the consistency of trace messages emitted by Rocket so that they all
begin with 'rocket::'.
This commit is contained in:
Matthew Pomes 2024-06-08 22:42:04 -05:00 committed by Sergio Benitez
parent 606cd61e3f
commit 6857b82ec4
2 changed files with 55 additions and 23 deletions

View File

@ -105,9 +105,13 @@ fn query_decls(route: &Route) -> Option<TokenStream> {
)*
if !__e.is_empty() {
::rocket::trace::span_info!("codegen",
::rocket::trace::span_info!(
"codegen",
"query string failed to match route declaration" =>
{ for _err in __e { ::rocket::trace::info!("{_err}"); } }
{ for _err in __e { ::rocket::trace::info!(
target: concat!("rocket::codegen::route::", module_path!()),
"{_err}"
); } }
);
return #Outcome::Forward((#__data, #Status::UnprocessableEntity));
@ -128,17 +132,27 @@ fn request_guard_decl(guard: &Guard) -> TokenStream {
let #ident: #ty = match <#ty as #FromRequest>::from_request(#__req).await {
#Outcome::Success(__v) => __v,
#Outcome::Forward(__e) => {
::rocket::trace::info!(name: "forward", parameter = stringify!(#ident),
type_name = stringify!(#ty), status = __e.code,
"request guard forwarding");
::rocket::trace::info!(
name: "forward",
target: concat!("rocket::codegen::route::", module_path!()),
parameter = stringify!(#ident),
type_name = stringify!(#ty),
status = __e.code,
"request guard forwarding"
);
return #Outcome::Forward((#__data, __e));
},
#[allow(unreachable_code)]
#Outcome::Error((__c, __e)) => {
::rocket::trace::info!(name: "failure", parameter = stringify!(#ident),
type_name = stringify!(#ty), reason = %#display_hack!(__e),
"request guard failed");
::rocket::trace::info!(
name: "failure",
target: concat!("rocket::codegen::route::", module_path!()),
parameter = stringify!(#ident),
type_name = stringify!(#ty),
reason = %#display_hack!(__e),
"request guard failed"
);
return #Outcome::Error(__c);
}
@ -155,9 +169,14 @@ fn param_guard_decl(guard: &Guard) -> TokenStream {
// Returned when a dynamic parameter fails to parse.
let parse_error = quote!({
::rocket::trace::info!(name: "forward", parameter = #name,
type_name = stringify!(#ty), reason = %#display_hack!(__error),
"path guard forwarding");
::rocket::trace::info!(
name: "forward",
target: concat!("rocket::codegen::route::", module_path!()),
parameter = #name,
type_name = stringify!(#ty),
reason = %#display_hack!(__error),
"path guard forwarding"
);
#Outcome::Forward((#__data, #Status::UnprocessableEntity))
});
@ -174,9 +193,12 @@ fn param_guard_decl(guard: &Guard) -> TokenStream {
},
#_None => {
::rocket::trace::error!(
target: concat!("rocket::codegen::route::", module_path!()),
"Internal invariant broken: dyn param {} not found.\n\
Please report this to the Rocket issue tracker.\n\
https://github.com/rwf2/Rocket/issues", #i);
https://github.com/rwf2/Rocket/issues",
#i
);
return #Outcome::Forward((#__data, #Status::InternalServerError));
}
@ -203,17 +225,27 @@ fn data_guard_decl(guard: &Guard) -> TokenStream {
let #ident: #ty = match <#ty as #FromData>::from_data(#__req, #__data).await {
#Outcome::Success(__d) => __d,
#Outcome::Forward((__d, __e)) => {
::rocket::trace::info!(name: "forward", parameter = stringify!(#ident),
type_name = stringify!(#ty), status = __e.code,
"data guard forwarding");
::rocket::trace::info!(
name: "forward",
target: concat!("rocket::codegen::route::", module_path!()),
parameter = stringify!(#ident),
type_name = stringify!(#ty),
status = __e.code,
"data guard forwarding"
);
return #Outcome::Forward((__d, __e));
}
#[allow(unreachable_code)]
#Outcome::Error((__c, __e)) => {
::rocket::trace::info!(name: "failure", parameter = stringify!(#ident),
type_name = stringify!(#ty), reason = %#display_hack!(__e),
"data guard failed");
::rocket::trace::info!(
name: "failure",
target: concat!("rocket::codegen::route::", module_path!()),
parameter = stringify!(#ident),
type_name = stringify!(#ty),
reason = %#display_hack!(__e),
"data guard failed"
);
return #Outcome::Error(__c);
}

View File

@ -39,10 +39,10 @@ impl RocketDynFmt {
return;
}
let workers = config.map(|c| c.workers).unwrap_or(num_cpus::get());
let colors = config.map(|c| c.cli_colors).unwrap_or(CliColors::Auto);
let level = config.map(|c| c.log_level).unwrap_or(Some(Level::INFO));
let format = config.map(|c| c.log_format).unwrap_or(TraceFormat::Pretty);
let workers = config.map_or(num_cpus::get(), |c| c.workers);
let colors = config.map_or(CliColors::Auto, |c| c.cli_colors);
let level = config.map_or(Some(Level::INFO), |c| c.log_level);
let format = config.map_or(TraceFormat::Pretty, |c| c.log_format);
let formatter = |format| match format {
TraceFormat::Pretty => Self::from(RocketFmt::<Pretty>::new(workers, colors, level)),
@ -57,7 +57,7 @@ impl RocketDynFmt {
if result.is_ok() {
assert!(HANDLE.set(reload_handle).is_ok());
} if let Some(handle) = HANDLE.get() {
} else if let Some(handle) = HANDLE.get() {
assert!(handle.modify(|layer| *layer = formatter(format)).is_ok());
}
}