impl NeqoQlog { /// Create an enabled `NeqoQlog` configuration backed by a file. /// /// # Errors /// /// Will return `qlog::Error` if it cannot write to the new file. pubfn enabled_with_file( mut qlog_path: PathBuf,
role: Role,
title: Option<String>,
description: Option<String>,
file_prefix: impl Display,
) -> Result<Self, qlog::Error> {
qlog_path.push(format!("{file_prefix}.sqlog"));
let file = OpenOptions::new()
.write(true) // As a server, the original DCID is chosen by the client. Using // create_new() prevents attackers from overwriting existing logs.
.create_new(true)
.open(&qlog_path)
.map_err(qlog::Error::IoError)?;
/// Create an enabled `NeqoQlog` configuration. /// /// # Errors /// /// Will return `qlog::Error` if it cannot write to the new log. pubfn enabled(mut streamer: QlogStreamer, qlog_path: PathBuf) -> Result<Self, qlog::Error> {
streamer.start_log()?;
/// If logging enabled, closure may generate an event to be logged. pubfn add_event_with_instant<F>(&self, f: F, now: Instant) where
F: FnOnce() -> Option<qlog::events::Event>,
{ self.add_event_with_stream(|s| { iflet Some(evt) = f() {
s.add_event_with_instant(evt, now)?;
}
Ok(())
});
}
/// If logging enabled, closure may generate an event to be logged. pubfn add_event_data_with_instant<F>(&self, f: F, now: Instant) where
F: FnOnce() -> Option<qlog::events::EventData>,
{ self.add_event_with_stream(|s| { iflet Some(ev_data) = f() {
s.add_event_data_with_instant(ev_data, now)?;
}
Ok(())
});
}
/// If logging enabled, closure may generate an event to be logged. /// /// This function is similar to [`NeqoQlog::add_event_data_with_instant`], /// but it does not take `now: Instant` as an input parameter. Instead, it /// internally calls [`std::time::Instant::now`]. Prefer calling /// [`NeqoQlog::add_event_data_with_instant`] when `now` is available, as it /// ensures consistency with the current time, which might differ from /// [`std::time::Instant::now`] (e.g., when using simulated time instead of /// real time). pubfn add_event_data_now<F>(&self, f: F) where
F: FnOnce() -> Option<qlog::events::EventData>,
{ self.add_event_with_stream(|s| { iflet Some(ev_data) = f() {
s.add_event_data_now(ev_data)?;
}
Ok(())
});
}
/// If logging enabled, closure is given the Qlog stream to write events and /// frames to. pubfn add_event_with_stream<F>(&self, f: F) where
F: FnOnce(&mut QlogStreamer) -> Result<(), qlog::Error>,
{ iflet Some(inner) = self.inner.borrow_mut().as_mut() { iflet Err(e) = f(&mut inner.streamer) { crate::do_log!(
::log::Level::Error, "Qlog event generation failed with error {}; closing qlog.",
e
);
*self.inner.borrow_mut() = None;
}
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.