Skip to content

Commit b6bc89f

Browse files
committed
Auto merge of #3115 - Turbo87:tracing, r=pietroalbini
Replace `log` and `env_logger` with `tracing` crates This brings us closer to being able to use structured logging and properly instrumenting some of functions. The change is mostly a drop-in replacement as described by https://docs.rs/tracing/0.1.22/tracing/#for-log-users. The only difference is the slightly changed log output format: ``` # before [2020-12-23T21:51:50Z INFO cargo_registry::app] test23 # after Dec 23 22:53:48.847 INFO cargo_registry::app: test23 ``` This could be massaged by using a custom `FormatEvent` implementation though, if we really need this to be formatted in a specific way. Otherwise there is also a JSON-based output format which might be beneficial in production for real structured logging. r? `@pietroalbini`
2 parents 2d82b5a + 8b36e01 commit b6bc89f

File tree

6 files changed

+126
-31
lines changed

6 files changed

+126
-31
lines changed

Cargo.lock

Lines changed: 115 additions & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ dialoguer = "0.7.1"
5454
diesel = { version = "1.4.0", features = ["postgres", "serde_json", "chrono", "r2d2"] }
5555
diesel_full_text_search = "1.0.0"
5656
dotenv = "0.15"
57-
env_logger = "0.8"
5857
failure = "0.1.1"
5958
flate2 = "1.0"
6059
futures-channel = { version = "0.3.1", default-features = false }
@@ -69,7 +68,6 @@ indexmap = "1.0.2"
6968
jemallocator = { version = "0.3", features = ['unprefixed_malloc_on_supported_platforms', 'profiling'] }
7069
lettre = { version = "0.10.0-alpha.1", default-features = false, features = ["file-transport", "smtp-transport", "native-tls", "hostname", "builder"] }
7170
license-exprs = "^1.4"
72-
log = "0.4"
7371
oauth2 = { version = "3.0.0", default-features = false, features = ["reqwest-010"] }
7472
parking_lot = "0.11"
7573
rand = "0.7"
@@ -85,6 +83,8 @@ tar = "0.4.16"
8583
tempfile = "3"
8684
tokio = { version = "0.2", default-features = false, features = ["net", "signal", "io-std"]}
8785
toml = "0.5"
86+
tracing = "0.1"
87+
tracing-subscriber = "0.2"
8888
url = "2.1"
8989

9090
[dev-dependencies]

src/bin/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
4545
});
4646

4747
// Initialize logging
48-
env_logger::init();
48+
tracing_subscriber::fmt::init();
4949

5050
let config = cargo_registry::Config::default();
5151
let client = Client::new();

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ extern crate derive_deref;
1515
#[macro_use]
1616
extern crate diesel;
1717
#[macro_use]
18-
extern crate log;
19-
#[macro_use]
2018
extern crate serde;
2119
#[macro_use]
2220
extern crate serde_json;
21+
#[macro_use]
22+
extern crate tracing;
2323

2424
pub use crate::{app::App, config::Config, uploaders::Uploader};
2525
use std::sync::Arc;

src/tests/all.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ extern crate diesel;
77
#[macro_use]
88
extern crate lazy_static;
99
#[macro_use]
10-
extern crate log;
11-
#[macro_use]
1210
extern crate serde;
1311
#[macro_use]
1412
extern crate serde_json;
13+
#[macro_use]
14+
extern crate tracing;
1515

1616
use crate::util::{RequestHelper, TestApp};
1717
use cargo_registry::{

src/tests/util.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ use url::Url;
4848
pub use conduit::{header, StatusCode};
4949

5050
pub fn init_logger() {
51-
let _ = env_logger::builder()
52-
.format_timestamp(None)
53-
.is_test(true)
51+
let _ = tracing_subscriber::fmt()
52+
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
53+
.without_time()
54+
.with_test_writer()
5455
.try_init();
5556
}
5657

0 commit comments

Comments
 (0)