Skip to content

Commit

Permalink
Auto merge of #74726 - oli-obk:tracing, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
Move from `log` to `tracing`

The only visible change is that we now get timestamps in our logs:

```
Jul 24 18:41:01.065 TRACE rustc_mir::transform::const_prop: skipping replace of Rvalue::Use(const () because it is already a const
Jul 24 18:41:01.065 TRACE rustc_mir::transform::const_prop: propagated into _2
Jul 24 18:41:01.065 TRACE rustc_mir::transform::const_prop: visit_constant: const ()
```

This PR was explicitly designed to be as low-impact as possible. We can now move to using the name `tracing` insteads of `log` on a crate-by-crate basis and use any of the other tracing features where desirable.

As far as I can tell this will allow tools to seamlessly keep working (since they are using `rustc_driver::init_log...`).

This is the first half of step 1 of the accepted `tracing` MCP (rust-lang/compiler-team#331)
  • Loading branch information
bors committed Aug 1, 2020
2 parents de10abf + c729037 commit 05762e3
Show file tree
Hide file tree
Showing 41 changed files with 161 additions and 89 deletions.
143 changes: 98 additions & 45 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/librustc_ast/Cargo.toml
Expand Up @@ -11,7 +11,7 @@ doctest = false

[dependencies]
rustc_serialize = { path = "../librustc_serialize" }
log = "0.4"
log = { package = "tracing", version = "0.1" }
scoped-tls = "1.0"
rustc_span = { path = "../librustc_span" }
rustc_data_structures = { path = "../librustc_data_structures" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_lowering/Cargo.toml
Expand Up @@ -11,7 +11,7 @@ doctest = false

[dependencies]
rustc_arena = { path = "../librustc_arena" }
log = { version = "0.4", features = ["release_max_level_info", "std"] }
log = { package = "tracing", version = "0.1" }
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
rustc_hir = { path = "../librustc_hir" }
rustc_target = { path = "../librustc_target" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_passes/Cargo.toml
Expand Up @@ -10,7 +10,7 @@ path = "lib.rs"

[dependencies]
itertools = "0.8"
log = "0.4"
log = { package = "tracing", version = "0.1" }
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
rustc_attr = { path = "../librustc_attr" }
rustc_data_structures = { path = "../librustc_data_structures" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_pretty/Cargo.toml
Expand Up @@ -10,7 +10,7 @@ path = "lib.rs"
doctest = false

[dependencies]
log = "0.4"
log = { package = "tracing", version = "0.1" }
rustc_span = { path = "../librustc_span" }
rustc_ast = { path = "../librustc_ast" }
rustc_target = { path = "../librustc_target" }
2 changes: 1 addition & 1 deletion src/librustc_builtin_macros/Cargo.toml
Expand Up @@ -11,7 +11,7 @@ doctest = false

[dependencies]
rustc_parse_format = { path = "../librustc_parse_format" }
log = "0.4"
log = { package = "tracing", version = "0.1" }
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
rustc_attr = { path = "../librustc_attr" }
rustc_data_structures = { path = "../librustc_data_structures" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/Cargo.toml
Expand Up @@ -15,7 +15,7 @@ bitflags = "1.0"
flate2 = "1.0"
libc = "0.2"
measureme = "0.7.1"
log = "0.4"
log = { package = "tracing", version = "0.1" }
rustc_middle = { path = "../librustc_middle" }
rustc-demangle = "0.1"
rustc_attr = { path = "../librustc_attr" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/Cargo.toml
Expand Up @@ -14,7 +14,7 @@ bitflags = "1.2.1"
cc = "1.0.1"
num_cpus = "1.0"
memmap = "0.7"
log = "0.4.5"
log = { package = "tracing", version = "0.1" }
libc = "0.2.50"
jobserver = "0.1.11"
tempfile = "3.1"
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_data_structures/Cargo.toml
Expand Up @@ -12,7 +12,7 @@ doctest = false
[dependencies]
ena = "0.14"
indexmap = "1"
log = "0.4"
log = { package = "tracing", version = "0.1" }
jobserver_crate = { version = "0.1.13", package = "jobserver" }
lazy_static = "1"
once_cell = { version = "1", features = ["parking_lot"] }
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_driver/Cargo.toml
Expand Up @@ -12,8 +12,8 @@ crate-type = ["dylib"]
[dependencies]
lazy_static = "1.0"
libc = "0.2"
log = "0.4"
env_logger = { version = "0.7", default-features = false }
log = { package = "tracing", version = "0.1.18", features = ["release_max_level_info"] }
tracing-subscriber = { version = "0.2.10", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] }
rustc_middle = { path = "../librustc_middle" }
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
rustc_target = { path = "../librustc_target" }
Expand Down
21 changes: 19 additions & 2 deletions src/librustc_driver/lib.rs
Expand Up @@ -1224,9 +1224,26 @@ pub fn install_ice_hook() {
}

/// This allows tools to enable rust logging without having to magically match rustc's
/// log crate version
/// log crate version.
pub fn init_rustc_env_logger() {
env_logger::init_from_env("RUSTC_LOG");
init_env_logger("RUSTC_LOG")
}

/// This allows tools to enable rust logging without having to magically match rustc's
/// log crate version. In contrast to `init_rustc_env_logger` it allows you to choose an env var
/// other than `RUSTC_LOG`.
pub fn init_env_logger(env: &str) {
// Don't register a dispatcher if there's no filter to print anything
match std::env::var(env) {
Err(_) => return,
Ok(s) if s.is_empty() => return,
Ok(_) => {}
}
let builder = tracing_subscriber::FmtSubscriber::builder();

let builder = builder.with_env_filter(tracing_subscriber::EnvFilter::from_env(env));

builder.init()
}

pub fn main() -> ! {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_errors/Cargo.toml
Expand Up @@ -10,7 +10,7 @@ path = "lib.rs"
doctest = false

[dependencies]
log = "0.4"
log = { package = "tracing", version = "0.1" }
rustc_serialize = { path = "../librustc_serialize" }
rustc_span = { path = "../librustc_span" }
rustc_data_structures = { path = "../librustc_data_structures" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_expand/Cargo.toml
Expand Up @@ -12,7 +12,7 @@ doctest = false

[dependencies]
rustc_serialize = { path = "../librustc_serialize" }
log = "0.4"
log = { package = "tracing", version = "0.1" }
rustc_span = { path = "../librustc_span" }
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
rustc_ast_passes = { path = "../librustc_ast_passes" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_hir/Cargo.toml
Expand Up @@ -18,5 +18,5 @@ rustc_span = { path = "../librustc_span" }
rustc_serialize = { path = "../librustc_serialize" }
rustc_ast = { path = "../librustc_ast" }
lazy_static = "1"
log = { version = "0.4", features = ["release_max_level_info", "std"] }
log = { package = "tracing", version = "0.1" }
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
2 changes: 1 addition & 1 deletion src/librustc_incremental/Cargo.toml
Expand Up @@ -11,7 +11,7 @@ doctest = false

[dependencies]
rustc_graphviz = { path = "../librustc_graphviz" }
log = "0.4"
log = { package = "tracing", version = "0.1" }
rand = "0.7"
rustc_middle = { path = "../librustc_middle" }
rustc_data_structures = { path = "../librustc_data_structures" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/Cargo.toml
Expand Up @@ -11,7 +11,7 @@ doctest = false

[dependencies]
rustc_graphviz = { path = "../librustc_graphviz" }
log = { version = "0.4", features = ["release_max_level_info", "std"] }
log = { package = "tracing", version = "0.1" }
rustc_middle = { path = "../librustc_middle" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_errors = { path = "../librustc_errors" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_interface/Cargo.toml
Expand Up @@ -11,7 +11,7 @@ doctest = false

[dependencies]
libc = "0.2"
log = "0.4"
log = { package = "tracing", version = "0.1" }
rayon = { version = "0.3.0", package = "rustc-rayon" }
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
rustc_ast = { path = "../librustc_ast" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/Cargo.toml
Expand Up @@ -9,7 +9,7 @@ name = "rustc_lint"
path = "lib.rs"

[dependencies]
log = "0.4"
log = { package = "tracing", version = "0.1" }
unicode-security = "0.0.5"
rustc_middle = { path = "../librustc_middle" }
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/Cargo.toml
Expand Up @@ -12,7 +12,7 @@ doctest = false
[dependencies]
flate2 = "1.0"
libc = "0.2"
log = "0.4"
log = { package = "tracing", version = "0.1" }
memmap = "0.7"
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
rustc_middle = { path = "../librustc_middle" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_middle/Cargo.toml
Expand Up @@ -13,7 +13,7 @@ doctest = false
rustc_arena = { path = "../librustc_arena" }
bitflags = "1.2.1"
scoped-tls = "1.0"
log = { version = "0.4", features = ["release_max_level_info", "std"] }
log = { package = "tracing", version = "0.1" }
rustc-rayon-core = "0.3.0"
polonius-engine = "0.12.0"
rustc_apfloat = { path = "../librustc_apfloat" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/Cargo.toml
Expand Up @@ -13,7 +13,7 @@ doctest = false
either = "1.5.0"
rustc_graphviz = { path = "../librustc_graphviz" }
itertools = "0.8"
log = "0.4"
log = { package = "tracing", version = "0.1" }
log_settings = "0.1.1"
polonius-engine = "0.12.0"
rustc_middle = { path = "../librustc_middle" }
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_mir/interpret/eval_context.rs
Expand Up @@ -822,11 +822,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
) -> InterpResult<'tcx> {
// FIXME: should we tell the user that there was a local which was never written to?
if let LocalValue::Live(Operand::Indirect(MemPlace { ptr, .. })) = local {
trace!("deallocating local");
// All locals have a backing allocation, even if the allocation is empty
// due to the local having ZST type.
let ptr = ptr.assert_ptr();
trace!("{:?}", self.memory.dump_alloc(ptr.alloc_id));
trace!("deallocating local: {:?}", self.memory.dump_alloc(ptr.alloc_id));
self.memory.deallocate_local(ptr)?;
};
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir_build/Cargo.toml
Expand Up @@ -11,7 +11,7 @@ doctest = false

[dependencies]
rustc_arena = { path = "../librustc_arena" }
log = "0.4"
log = { package = "tracing", version = "0.1" }
rustc_middle = { path = "../librustc_middle" }
rustc_apfloat = { path = "../librustc_apfloat" }
rustc_attr = { path = "../librustc_attr" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_parse/Cargo.toml
Expand Up @@ -11,7 +11,7 @@ doctest = false

[dependencies]
bitflags = "1.0"
log = "0.4"
log = { package = "tracing", version = "0.1" }
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_feature = { path = "../librustc_feature" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/Cargo.toml
Expand Up @@ -9,7 +9,7 @@ name = "rustc_passes"
path = "lib.rs"

[dependencies]
log = "0.4"
log = { package = "tracing", version = "0.1" }
rustc_middle = { path = "../librustc_middle" }
rustc_attr = { path = "../librustc_attr" }
rustc_data_structures = { path = "../librustc_data_structures" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_privacy/Cargo.toml
Expand Up @@ -17,4 +17,4 @@ rustc_typeck = { path = "../librustc_typeck" }
rustc_session = { path = "../librustc_session" }
rustc_span = { path = "../librustc_span" }
rustc_data_structures = { path = "../librustc_data_structures" }
log = "0.4"
log = { package = "tracing", version = "0.1" }
2 changes: 1 addition & 1 deletion src/librustc_query_system/Cargo.toml
Expand Up @@ -11,7 +11,7 @@ doctest = false

[dependencies]
rustc_arena = { path = "../librustc_arena" }
log = { version = "0.4", features = ["release_max_level_info", "std"] }
log = { package = "tracing", version = "0.1" }
rustc-rayon-core = "0.3.0"
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_errors = { path = "../librustc_errors" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_resolve/Cargo.toml
Expand Up @@ -12,7 +12,7 @@ doctest = false

[dependencies]
bitflags = "1.2.1"
log = "0.4"
log = { package = "tracing", version = "0.1" }
rustc_ast = { path = "../librustc_ast" }
rustc_arena = { path = "../librustc_arena" }
rustc_middle = { path = "../librustc_middle" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_save_analysis/Cargo.toml
Expand Up @@ -9,7 +9,7 @@ name = "rustc_save_analysis"
path = "lib.rs"

[dependencies]
log = "0.4"
log = { package = "tracing", version = "0.1" }
rustc_middle = { path = "../librustc_middle" }
rustc_ast = { path = "../librustc_ast" }
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_session/Cargo.toml
Expand Up @@ -11,7 +11,7 @@ path = "lib.rs"
[dependencies]
bitflags = "1.2.1"
getopts = "0.2"
log = "0.4"
log = { package = "tracing", version = "0.1" }
rustc_errors = { path = "../librustc_errors" }
rustc_feature = { path = "../librustc_feature" }
rustc_target = { path = "../librustc_target" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_span/Cargo.toml
Expand Up @@ -18,6 +18,6 @@ rustc_arena = { path = "../librustc_arena" }
scoped-tls = "1.0"
unicode-width = "0.1.4"
cfg-if = "0.1.2"
log = "0.4"
log = { package = "tracing", version = "0.1" }
sha-1 = "0.8"
md-5 = "0.8"
2 changes: 1 addition & 1 deletion src/librustc_symbol_mangling/Cargo.toml
Expand Up @@ -10,7 +10,7 @@ path = "lib.rs"
doctest = false

[dependencies]
log = "0.4"
log = { package = "tracing", version = "0.1" }
punycode = "0.4.0"
rustc-demangle = "0.1.16"

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_target/Cargo.toml
Expand Up @@ -10,7 +10,7 @@ path = "lib.rs"

[dependencies]
bitflags = "1.2.1"
log = "0.4"
log = { package = "tracing", version = "0.1" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_macros = { path = "../librustc_macros" }
rustc_serialize = { path = "../librustc_serialize" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trait_selection/Cargo.toml
Expand Up @@ -11,7 +11,7 @@ doctest = false

[dependencies]
rustc_parse_format = { path = "../librustc_parse_format" }
log = { version = "0.4", features = ["release_max_level_info", "std"] }
log = { package = "tracing", version = "0.1" }
rustc_attr = { path = "../librustc_attr" }
rustc_middle = { path = "../librustc_middle" }
rustc_ast = { path = "../librustc_ast" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_traits/Cargo.toml
Expand Up @@ -9,7 +9,7 @@ name = "rustc_traits"
path = "lib.rs"

[dependencies]
log = { version = "0.4" }
log = { package = "tracing", version = "0.1" }
rustc_middle = { path = "../librustc_middle" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_hir = { path = "../librustc_hir" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ty/Cargo.toml
Expand Up @@ -9,7 +9,7 @@ name = "rustc_ty"
path = "lib.rs"

[dependencies]
log = "0.4"
log = { package = "tracing", version = "0.1" }
rustc_middle = { path = "../librustc_middle" }
rustc_data_structures = { path = "../librustc_data_structures" }
rustc_errors = { path = "../librustc_errors" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/Cargo.toml
Expand Up @@ -12,7 +12,7 @@ doctest = false

[dependencies]
rustc_arena = { path = "../librustc_arena" }
log = "0.4"
log = { package = "tracing", version = "0.1" }
rustc_middle = { path = "../librustc_middle" }
rustc_attr = { path = "../librustc_attr" }
rustc_data_structures = { path = "../librustc_data_structures" }
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/lib.rs
Expand Up @@ -14,7 +14,6 @@
#![feature(never_type)]
#![recursion_limit = "256"]

extern crate env_logger;
#[macro_use]
extern crate lazy_static;
extern crate rustc_ast;
Expand Down Expand Up @@ -90,7 +89,8 @@ pub fn main() {
};
rustc_driver::set_sigpipe_handler();
rustc_driver::install_ice_hook();
env_logger::init_from_env("RUSTDOC_LOG");
rustc_driver::init_env_logger("RUSTDOC_LOG");

let res = std::thread::Builder::new()
.stack_size(thread_stack_size)
.spawn(move || get_args().map(|args| main_args(&args)).unwrap_or(1))
Expand Down
2 changes: 1 addition & 1 deletion src/tools/compiletest/Cargo.toml
Expand Up @@ -8,7 +8,7 @@ edition = "2018"
diff = "0.1.10"
env_logger = { version = "0.7", default-features = false }
getopts = "0.2"
log = "0.4"
log = { package = "tracing", version = "0.1" }
regex = "1.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions src/tools/error_index_generator/main.rs
@@ -1,7 +1,7 @@
#![feature(rustc_private)]

extern crate env_logger;
extern crate rustc_ast;
extern crate rustc_driver;
extern crate rustc_span;

use std::cell::RefCell;
Expand Down Expand Up @@ -282,7 +282,7 @@ fn parse_args() -> (OutputFormat, PathBuf) {
}

fn main() {
env_logger::init();
rustc_driver::init_env_logger("RUST_LOG");
let (format, dst) = parse_args();
let result = rustc_ast::with_default_session_globals(move || main_with_result(format, &dst));
if let Err(e) = result {
Expand Down
3 changes: 3 additions & 0 deletions src/tools/tidy/src/deps.rs
Expand Up @@ -166,6 +166,9 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
"termcolor",
"termize",
"thread_local",
"tracing",
"tracing-attributes",
"tracing-core",
"typenum",
"unicode-normalization",
"unicode-script",
Expand Down

0 comments on commit 05762e3

Please sign in to comment.