Skip to content

Commit

Permalink
Switch logging target when the response to capabilities is a bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
glandium committed Jun 21, 2024
1 parent 5b21a50 commit 075c9b0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/hg_connect_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,32 @@ fn http_send_info(data: &mut HttpThreadData) {
None
}
};
if data.logger.as_ref().map(|logger| logger.log_target())

Check failure on line 606 in src/hg_connect_http.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-latest, 1.79.0)

redundant closure

error: redundant closure --> src/hg_connect_http.rs:606:41 | 606 | if data.logger.as_ref().map(|logger| logger.log_target()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `super::logging::LoggingWriter::log_target` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls note: the lint level is defined here --> src/main.rs:27:9 | 27 | #![deny(clippy::redundant_closure_for_method_calls)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Check failure on line 606 in src/hg_connect_http.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest, 1.79.0)

redundant closure

error: redundant closure --> src/hg_connect_http.rs:606:41 | 606 | if data.logger.as_ref().map(|logger| logger.log_target()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `super::logging::LoggingWriter::log_target` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls note: the lint level is defined here --> src/main.rs:27:9 | 27 | #![deny(clippy::redundant_closure_for_method_calls)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
== Some("raw-wire::capabilities")
{
match content_type.as_deref() {
Some("application/mercurial-0.1") | Some("application/mercurial-0.2") => {}

Check failure on line 610 in src/hg_connect_http.rs

View workflow job for this annotation

GitHub Actions / clippy (ubuntu-latest, 1.79.0)

unnested or-patterns

error: unnested or-patterns --> src/hg_connect_http.rs:610:21 | 610 | Some("application/mercurial-0.1") | Some("application/mercurial-0.2") => {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns note: the lint level is defined here --> src/main.rs:38:9 | 38 | #![deny(clippy::unnested_or_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: nest the patterns | 610 | Some("application/mercurial-0.1" | "application/mercurial-0.2") => {} | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check failure on line 610 in src/hg_connect_http.rs

View workflow job for this annotation

GitHub Actions / clippy (macos-latest, 1.79.0)

unnested or-patterns

error: unnested or-patterns --> src/hg_connect_http.rs:610:21 | 610 | Some("application/mercurial-0.1") | Some("application/mercurial-0.2") => {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns note: the lint level is defined here --> src/main.rs:38:9 | 38 | #![deny(clippy::unnested_or_patterns)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: nest the patterns | 610 | Some("application/mercurial-0.1" | "application/mercurial-0.2") => {} | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_ => {
// If the response to the capabilities request is a bundle, log in
// a different category.
// Ideally we'd log the headers too with the switched logger, but
// it's too late for that.
trace!(
target: "raw-wire::capabilities",
"Not a capabilities response; switching to clonebundle.",
);
if log_enabled!(target: "raw-wire::clonebundle", log::Level::Trace) {
let mut writer = LoggingWriter::new_hex(
"raw-wire::clonebundle".to_string(),
log::Level::Trace,
std::io::sink(),
);
writer.set_direction(logging::Direction::Receive);
data.logger = Some(writer);
}
}
}
}
data.sender
.send(Either::Left(HttpResponseInfo {
http_status: http_status as usize,
Expand Down
4 changes: 4 additions & 0 deletions src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,10 @@ impl<'a, W: Write> LoggingWriter<'a, W> {
pub fn set_direction(&mut self, direction: Direction) {
self.log.direction = direction;
}

pub fn log_target(&self) -> &str {
&self.log.target
}
}

impl<'a, W: Write> Write for LoggingWriter<'a, W> {
Expand Down

0 comments on commit 075c9b0

Please sign in to comment.