Skip to content

Commit

Permalink
fix even more linting
Browse files Browse the repository at this point in the history
  • Loading branch information
MexicanAce committed Sep 15, 2023
1 parent 667c20e commit 118e92d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 56 deletions.
100 changes: 44 additions & 56 deletions src/logging_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,68 +33,56 @@ impl Middleware<Meta> for LoggingMiddleware {
F: FnOnce(Request, Meta) -> X + Send,
X: Future<Output = Option<Response>> + Send + 'static,
{
match &request {
Request::Single(call) => {
match call {
Call::MethodCall(method_call) => {
match self.log_level_filter {
LevelFilter::Debug => {
let full_params = match &method_call.params {
Params::Array(values) => {
if values.is_empty() {
String::default()
} else {
format!("with [{}]", values.iter().join(", "))
}
}
_ => String::default(),
};

log::debug!(
"{} was called {}",
method_call.method.cyan(),
full_params
);
if let Request::Single(Call::MethodCall(method_call)) = &request {
match self.log_level_filter {
LevelFilter::Debug => {
let full_params = match &method_call.params {
Params::Array(values) => {
if values.is_empty() {
String::default()
} else {
format!("with [{}]", values.iter().join(", "))
}
_ => {
// Generate truncated params for requests with massive payloads
let truncated_params = match &method_call.params {
Params::Array(values) => {
if values.is_empty() {
String::default()
} else {
format!(
"with [{}]",
values
.iter()
.map(|s| {
let s_str = s.to_string();
if s_str.len() > 70 {
format!("{:.67}...", s_str)
} else {
s_str
}
})
.collect::<Vec<String>>()
.join(", ")
)
}
}
_ => String::default(),
};
}
_ => String::default(),
};

log::info!(
"{} was called {}",
method_call.method.cyan(),
truncated_params
);
log::debug!("{} was called {}", method_call.method.cyan(), full_params);
}
_ => {
// Generate truncated params for requests with massive payloads
let truncated_params = match &method_call.params {
Params::Array(values) => {
if values.is_empty() {
String::default()
} else {
format!(
"with [{}]",
values
.iter()
.map(|s| {
let s_str = s.to_string();
if s_str.len() > 70 {
format!("{:.67}...", s_str)
} else {
s_str
}
})
.collect::<Vec<String>>()
.join(", ")
)
}
}
}
_ => {}
_ => String::default(),
};

log::info!(
"{} was called {}",
method_call.method.cyan(),
truncated_params
);
}
}
_ => {}
};

Either::Left(Box::pin(next(request, meta)))
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ pub const RICH_WALLETS: [(&str, &str); 10] = [
),
];

#[allow(clippy::too_many_arguments)]
async fn build_json_http<
S: std::marker::Sync + std::marker::Send + 'static + ForkSource + std::fmt::Debug,
>(
Expand Down

0 comments on commit 118e92d

Please sign in to comment.