Browse Source

Improve logs

ng
Rodolphe Bréard 3 weeks ago
parent
commit
e036e14ad5
Failed to extract signature
  1. 6
      src/config.rs
  2. 10
      src/http.rs
  3. 6
      src/main.rs

6
src/config.rs

@ -150,9 +150,9 @@ pub fn load<P: AsRef<Path> + std::fmt::Debug>(config_dir: P) -> Result<AcmedConf
.collect::<Vec<_>>(),
)
.build()?;
tracing::trace!(?settings, "loaded config");
tracing::trace!("loaded config" = ?settings);
let config: AcmedConfig = settings.try_deserialize().context("invalid setting")?;
tracing::debug!(?config, "computed config");
tracing::debug!("computed config" = ?config);
Ok(config)
}
@ -170,7 +170,7 @@ fn get_files(config_dir: &Path) -> Result<Vec<PathBuf>> {
}
}
file_lst.sort();
tracing::debug!(files = ?file_lst, "configuration files found");
tracing::debug!("configuration files found" = ?file_lst);
Ok(file_lst)
}

10
src/http.rs

@ -56,7 +56,7 @@ impl HttpRoutine {
let (tx, rx) = mpsc::unbounded_channel();
let mut endpoints = HashMap::with_capacity(config.endpoint.len());
for (name, edp) in &config.endpoint {
tracing::debug!(name, "loading endpoint");
tracing::debug!("endpoint name" = name, "loading endpoint");
let client = get_http_client(config.get_global_root_certs(), &edp.root_certificates);
let endpoint = HttpEndpoint { client };
endpoints.insert(name.to_owned(), endpoint);
@ -74,14 +74,14 @@ impl HttpRoutine {
pub(super) async fn run(mut self) {
tracing::trace!("starting the http routine");
while let Some(raw_req) = self.rx.recv().await {
tracing::debug!(request = ?raw_req.request, "new http request");
tracing::debug!("new http request" = ?raw_req.request);
match self.endpoints.get(&raw_req.endpoint) {
Some(edp) => {
let ret = edp.client.execute(raw_req.request).await;
let _ = raw_req.tx.send(ret);
}
None => {
tracing::error!(endpoint = raw_req.endpoint, "endpoint not found");
tracing::error!("endpoint name" = raw_req.endpoint, "endpoint not found");
}
}
}
@ -95,9 +95,9 @@ macro_rules! add_root_cert {
match get_cert_pem(cert_path) {
Ok(cert) => {
$builder = $builder.add_root_certificate(cert);
tracing::debug!(?cert_path, "root certificate loaded");
tracing::debug!("path" = %cert_path.display(), "root certificate loaded");
}
Err(e) => tracing::error!(?cert_path, "{e:#?}",),
Err(e) => tracing::error!(path = ?cert_path, error = "{e:#?}", "unable to load root certificate"),
}
}
};

6
src/main.rs

@ -24,7 +24,7 @@ fn main() {
// Initialize the logging system
log::init(args.log_level, !args.log.log_stderr);
tracing::trace!(?args, "computed args");
tracing::trace!("computed args" = ?args);
// Load the configuration
let cfg = match config::load(args.config.as_path()) {
@ -70,7 +70,7 @@ async fn debug_remove_me(http_client: crate::http::HttpClient) {
Request::new(Method::GET, Url::parse("https://example.invalid").unwrap()),
)
.await;
tracing::debug!(response = ?rsp, "response received");
tracing::debug!("response received" = ?rsp);
let rsp = http_client
.send(
"my-ca",
@ -80,7 +80,7 @@ async fn debug_remove_me(http_client: crate::http::HttpClient) {
),
)
.await;
tracing::debug!(response = ?rsp, "response received");
tracing::debug!("response received" = ?rsp);
}
#[tracing::instrument(level = "trace", err(Debug))]

Loading…
Cancel
Save