Skip to content

Commit 1d27020

Browse files
committed
import tracing log macros where possible
1 parent 86dd166 commit 1d27020

File tree

14 files changed

+52
-44
lines changed

14 files changed

+52
-44
lines changed

src/build_queue.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{Config, Index, Metrics, RustwideBuilder};
88
use anyhow::Context;
99

1010
use crates_index_diff::Change;
11-
use tracing::{debug, info};
11+
use tracing::{debug, info, warn};
1212

1313
use git2::Oid;
1414
use std::sync::Arc;
@@ -239,11 +239,9 @@ fn retry<T>(mut f: impl FnMut() -> Result<T>, max_attempts: u32) -> Result<T> {
239239
return Err(err);
240240
} else {
241241
let sleep_for = 2u32.pow(attempt);
242-
tracing::warn!(
242+
warn!(
243243
"got error on attempt {}, will try again after {}s:\n{:?}",
244-
attempt,
245-
sleep_for,
246-
err
244+
attempt, sleep_for, err
247245
);
248246
thread::sleep(Duration::from_secs(sleep_for as u64));
249247
}

src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::env::VarError;
44
use std::error::Error;
55
use std::path::PathBuf;
66
use std::str::FromStr;
7+
use tracing::trace;
78

89
#[derive(Debug)]
910
pub struct Config {
@@ -205,7 +206,7 @@ where
205206
.map(Some)
206207
.with_context(|| format!("failed to parse configuration variable {}", var))?),
207208
Err(VarError::NotPresent) => {
208-
tracing::trace!("optional configuration variable {} is not set", var);
209+
trace!("optional configuration variable {} is not set", var);
209210
Ok(None)
210211
}
211212
Err(VarError::NotUnicode(_)) => Err(anyhow!("configuration variable {} is not UTF-8", var)),

src/docbuilder/rustwide_builder.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ impl RustwideBuilder {
160160
// NOTE: this ignores the error so that you can still run a build without rustfmt.
161161
// This should only happen if you run a build for the first time when rustfmt isn't available.
162162
if let Err(err) = self.toolchain.add_component(&self.workspace, "rustfmt") {
163-
tracing::warn!("failed to install rustfmt: {}", err);
164-
tracing::info!("continuing anyway, since this must be the first build");
163+
warn!("failed to install rustfmt: {}", err);
164+
info!("continuing anyway, since this must be the first build");
165165
}
166166

167167
self.rustc_version = self.detect_rustc_version()?;
@@ -486,7 +486,7 @@ impl RustwideBuilder {
486486
// won't lead to non-existing docs.
487487
for prefix in &["rustdoc", "sources"] {
488488
let prefix = format!("{}/{}/{}/", prefix, name, version);
489-
tracing::debug!("cleaning old storage folder {}", prefix);
489+
debug!("cleaning old storage folder {}", prefix);
490490
self.storage.delete_prefix(&prefix)?;
491491
}
492492
}
@@ -615,8 +615,8 @@ impl RustwideBuilder {
615615
let doc_coverage = match self.get_coverage(target, build, metadata, limits) {
616616
Ok(cov) => cov,
617617
Err(err) => {
618-
tracing::info!("error when trying to get coverage: {}", err);
619-
tracing::info!("continuing anyways.");
618+
info!("error when trying to get coverage: {}", err);
619+
info!("continuing anyways.");
620620
None
621621
}
622622
};

src/index/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::{path::PathBuf, process::Command};
22

33
use anyhow::Context;
4+
use tracing::debug;
45
use url::Url;
56

67
use self::api::Api;
@@ -90,9 +91,9 @@ impl Index {
9091
pub(crate) fn crates(&self) -> Result<crates_index::Index> {
9192
// First ensure the index is up to date, peeking will pull the latest changes without
9293
// affecting anything else.
93-
tracing::debug!("Updating index");
94+
debug!("Updating index");
9495
self.diff()?.peek_changes()?;
95-
tracing::debug!("Opening with `crates_index`");
96+
debug!("Opening with `crates_index`");
9697
// crates_index requires the repo url to match the existing origin or it tries to reinitialize the repo
9798
let repo_url = self
9899
.repository_url

src/storage/s3.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::{Blob, FileRange, StorageTransaction};
22
use crate::{Config, Metrics};
33
use anyhow::{Context, Error};
44
use aws_sdk_s3::{
5-
error,
5+
error as s3_error,
66
model::{Delete, ObjectIdentifier, Tag, Tagging},
77
types::SdkError,
88
Client, Endpoint, Region, RetryConfig,
@@ -15,6 +15,7 @@ use futures_util::{
1515
};
1616
use std::{io::Write, sync::Arc};
1717
use tokio::runtime::Runtime;
18+
use tracing::{error, warn};
1819

1920
const PUBLIC_ACCESS_TAG: &str = "static-cloudfront-access";
2021
const PUBLIC_ACCESS_VALUE: &str = "allow";
@@ -83,7 +84,7 @@ impl S3Backend {
8384
{
8485
Ok(_) => Ok(true),
8586
Err(SdkError::ServiceError { err, raw })
86-
if (matches!(err.kind, error::HeadObjectErrorKind::NotFound(_))
87+
if (matches!(err.kind, s3_error::HeadObjectErrorKind::NotFound(_))
8788
|| raw.http().status() == http::StatusCode::NOT_FOUND) =>
8889
{
8990
Ok(false)
@@ -174,7 +175,7 @@ impl S3Backend {
174175
.send()
175176
.map_err(|err| match err {
176177
SdkError::ServiceError { err, raw }
177-
if (matches!(err.kind, error::GetObjectErrorKind::NoSuchKey(_))
178+
if (matches!(err.kind, s3_error::GetObjectErrorKind::NoSuchKey(_))
178179
|| raw.http().status() == http::StatusCode::NOT_FOUND) =>
179180
{
180181
super::PathNotFoundError.into()
@@ -261,7 +262,7 @@ impl<'a> StorageTransaction for S3StorageTransaction<'a> {
261262
self.s3.metrics.uploaded_files_total.inc();
262263
})
263264
.map_err(|err| {
264-
tracing::warn!("Failed to upload blob to S3: {:?}", err);
265+
warn!("Failed to upload blob to S3: {:?}", err);
265266
// Reintroduce failed blobs for a retry
266267
blob
267268
}),
@@ -324,7 +325,7 @@ impl<'a> StorageTransaction for S3StorageTransaction<'a> {
324325

325326
if let Some(errs) = resp.errors {
326327
for err in &errs {
327-
tracing::error!("error deleting file from s3: {:?}", err);
328+
error!("error deleting file from s3: {:?}", err);
328329
}
329330

330331
anyhow::bail!("deleting from s3 failed");

src/test/fakes.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use chrono::{DateTime, Utc};
1010
use postgres::Client;
1111
use std::collections::{HashMap, HashSet};
1212
use std::sync::Arc;
13+
use tracing::debug;
1314

1415
#[must_use = "FakeRelease does nothing until you call .create()"]
1516
pub(crate) struct FakeRelease<'a> {
@@ -303,14 +304,14 @@ impl<'a> FakeRelease<'a> {
303304
.with_context(|| format!("failed to create {}", path.display()))?;
304305
}
305306
let file = base_path.join(&path);
306-
tracing::debug!("writing file {}", file.display());
307+
debug!("writing file {}", file.display());
307308
fs::write(file, data)?;
308309
}
309310
Ok(())
310311
};
311312

312313
let upload_files = |kind: FileKind, source_directory: &Path| {
313-
tracing::debug!(
314+
debug!(
314315
"adding directory {:?} from {}",
315316
kind,
316317
source_directory.display()
@@ -324,7 +325,7 @@ impl<'a> FakeRelease<'a> {
324325
(source_archive_path(&package.name, &package.version), false)
325326
}
326327
};
327-
tracing::debug!("store in archive: {:?}", archive);
328+
debug!("store in archive: {:?}", archive);
328329
let (files_list, new_alg) = crate::db::add_path_into_remote_archive(
329330
&storage,
330331
&archive,
@@ -347,11 +348,11 @@ impl<'a> FakeRelease<'a> {
347348
}
348349
};
349350

350-
tracing::debug!("before upload source");
351+
debug!("before upload source");
351352
let source_tmp = create_temp_dir();
352353
store_files_into(&self.source_files, source_tmp.path())?;
353354
let (source_meta, algs) = upload_files(FileKind::Sources, source_tmp.path())?;
354-
tracing::debug!("added source files {}", source_meta);
355+
debug!("added source files {}", source_meta);
355356

356357
// If the test didn't add custom builds, inject a default one
357358
if self.builds.is_empty() {
@@ -370,19 +371,19 @@ impl<'a> FakeRelease<'a> {
370371

371372
// store default target files
372373
store_files_into(&rustdoc_files, rustdoc_path)?;
373-
tracing::debug!("added rustdoc files");
374+
debug!("added rustdoc files");
374375

375376
for target in &package.targets[1..] {
376377
let platform = target.src_path.as_ref().unwrap();
377378
let platform_dir = rustdoc_path.join(platform);
378379
fs::create_dir(&platform_dir)?;
379380

380381
store_files_into(&rustdoc_files, &platform_dir)?;
381-
tracing::debug!("added platform files for {}", platform);
382+
debug!("added platform files for {}", platform);
382383
}
383384

384385
let (rustdoc_meta, _) = upload_files(FileKind::Rustdoc, rustdoc_path)?;
385-
tracing::debug!("uploaded rustdoc files: {}", rustdoc_meta);
386+
debug!("uploaded rustdoc files: {}", rustdoc_meta);
386387
}
387388

388389
let repository = match self.github_stats {

src/test/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use reqwest::{
1919
};
2020
use std::{fs, net::SocketAddr, panic, sync::Arc, time::Duration};
2121
use tokio::runtime::Runtime;
22-
use tracing::error;
22+
use tracing::{debug, error};
2323

2424
#[track_caller]
2525
pub(crate) fn wrapper(f: impl FnOnce(&TestEnvironment) -> Result<()>) {
@@ -536,13 +536,13 @@ impl TestFrontend {
536536

537537
pub(crate) fn get(&self, url: &str) -> RequestBuilder {
538538
let url = self.build_url(url);
539-
tracing::debug!("getting {url}");
539+
debug!("getting {url}");
540540
self.client.request(Method::GET, url)
541541
}
542542

543543
pub(crate) fn get_no_redirect(&self, url: &str) -> RequestBuilder {
544544
let url = self.build_url(url);
545-
tracing::debug!("getting {url} (no redirects)");
545+
debug!("getting {url} (no redirects)");
546546
self.client_no_redirect.request(Method::GET, url)
547547
}
548548
}

src/utils/consistency/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use self::diff::{Diff, Diffable};
22
use crate::Index;
33
use anyhow::Context;
4+
use tracing::info;
45

56
mod data;
67
mod db;
@@ -16,17 +17,17 @@ pub fn run_check(
1617
anyhow::bail!("TODO: only a --dry-run synchronization is supported currently");
1718
}
1819

19-
tracing::info!("Loading data from database...");
20+
info!("Loading data from database...");
2021
let timer = std::time::Instant::now();
2122
let db_data =
2223
self::db::load(conn).context("Loading crate data from database for consistency check")?;
23-
tracing::info!("...loaded in {:?}", timer.elapsed());
24+
info!("...loaded in {:?}", timer.elapsed());
2425

2526
tracing::info!("Loading data from index...");
2627
let timer = std::time::Instant::now();
2728
let index_data =
2829
self::index::load(index).context("Loading crate data from index for consistency check")?;
29-
tracing::info!("...loaded in {:?}", timer.elapsed());
30+
info!("...loaded in {:?}", timer.elapsed());
3031

3132
let diff = db_data.diff(index_data);
3233

src/utils/daemon.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use anyhow::{anyhow, Context as _, Error};
1010
use std::sync::Arc;
1111
use std::thread;
1212
use std::time::{Duration, Instant};
13-
use tracing::{debug, info};
13+
use tracing::{debug, error, info};
1414

1515
/// Run the registry watcher
1616
/// NOTE: this should only be run once, otherwise crates would be added
@@ -30,7 +30,7 @@ pub fn watch_registry(
3030
}
3131
Ok(None) => {}
3232
Err(err) => {
33-
tracing::error!(
33+
error!(
3434
"queue locked because of invalid last_seen_index_reference in database: {:?}",
3535
err
3636
);

src/utils/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use anyhow::Result;
2424
use postgres::Client;
2525
use serde::de::DeserializeOwned;
2626
use serde::Serialize;
27+
use tracing::error;
2728
pub(crate) mod sized_buffer;
2829

2930
pub(crate) const APP_USER_AGENT: &str = concat!(
@@ -37,7 +38,7 @@ pub(crate) fn report_error(err: &anyhow::Error) {
3738
sentry_anyhow::capture_anyhow(err);
3839
} else {
3940
// Debug-format for anyhow errors includes context & backtrace
40-
tracing::error!("{:?}", err);
41+
error!("{:?}", err);
4142
}
4243
}
4344

src/web/metrics.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use iron::prelude::*;
66
use iron::status::Status;
77
use prometheus::{Encoder, HistogramVec, TextEncoder};
88
use std::time::{Duration, Instant};
9+
#[cfg(test)]
10+
use tracing::debug;
911

1012
pub(super) fn metrics_handler(req: &mut Request) -> IronResult<Response> {
1113
let metrics = extension!(req, Metrics);
@@ -93,7 +95,7 @@ impl<'a> RenderingTimesRecorder<'a> {
9395
fn record_current(&mut self) {
9496
if let Some(current) = self.current.take() {
9597
#[cfg(test)]
96-
tracing::debug!(
98+
debug!(
9799
"rendering time - {}: {:?}",
98100
current.step,
99101
current.start.elapsed()

src/web/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,9 @@ fn match_version(
363363
VersionReq::STAR
364364
} else {
365365
VersionReq::parse(&req_version).map_err(|err| {
366-
tracing::info!(
366+
info!(
367367
"could not parse version requirement \"{}\": {:?}",
368-
req_version,
369-
err
368+
req_version, err
370369
);
371370
Nope::VersionNotFound
372371
})?

src/web/page/templates.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use postgres::Client;
99
use serde_json::Value;
1010
use std::{collections::HashMap, fmt, path::PathBuf};
1111
use tera::{Result as TeraResult, Tera};
12+
use tracing::{error, trace};
1213
use walkdir::WalkDir;
1314

1415
const TEMPLATES_DIRECTORY: &str = "templates";
@@ -21,13 +22,13 @@ pub(crate) struct TemplateData {
2122

2223
impl TemplateData {
2324
pub(crate) fn new(conn: &mut Client) -> Result<Self> {
24-
tracing::trace!("Loading templates");
25+
trace!("Loading templates");
2526

2627
let data = Self {
2728
templates: load_templates(conn)?,
2829
};
2930

30-
tracing::trace!("Finished loading templates");
31+
trace!("Finished loading templates");
3132

3233
Ok(data)
3334
}
@@ -84,7 +85,7 @@ pub(super) fn load_templates(conn: &mut Client) -> Result<Tera> {
8485
&mut tera,
8586
"rustc_resource_suffix",
8687
Value::String(load_rustc_resource_suffix(conn).unwrap_or_else(|err| {
87-
tracing::error!("Failed to load rustc resource suffix: {:?}", err);
88+
error!("Failed to load rustc resource suffix: {:?}", err);
8889
// This is not fatal because the server might be started before essential files are
8990
// generated during development. Returning "???" provides a degraded UX, but allows the
9091
// server to start every time.

0 commit comments

Comments
 (0)