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 bce8ec4 commit 21d9b5f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/hg_connect_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,31 @@ fn http_send_info(data: &mut HttpThreadData) {
None
}
};
if data.logger.as_ref().map(LoggingWriter::log_target) == Some("raw-wire::capabilities")
{
match content_type.as_deref() {
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 21d9b5f

Please sign in to comment.