Skip to content

Commit 1de6278

Browse files
committed
improve debug logging to use an env var
It used to be "always on" whenever it was compiled in, which was annoying, since sometimes you would want to quickly test to see if your new code worked without the full overhead of logging.
1 parent 78caab7 commit 1de6278

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ rand = "0.3"
1515
num_cpus = "1.0"
1616
deque = "0.3.1"
1717
libc = "0.2.16"
18+
lazy_static = "0.2.2"
1819

1920
[dev-dependencies]
2021
compiletest_rs = "0.2.1"

src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#![cfg_attr(test, feature(conservative_impl_trait))]
33

44
extern crate deque;
5+
#[macro_use]
6+
extern crate lazy_static;
57
extern crate libc;
68
extern crate num_cpus;
79
extern crate rand;

src/log.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
//! Debug Logging
2+
//!
3+
//! To use in a debug build, set the env var `RAYON_RS_LOG=1`. In a
4+
//! release build, logs are compiled out. You will have to change
5+
//! `DUMP_LOGS` to be `true`.
26
7+
use std::env;
38
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT};
49

510
#[derive(Debug)]
@@ -23,11 +28,15 @@ pub enum Event {
2328
LostJob { worker: usize },
2429
}
2530

26-
pub const DUMP_LOGS: bool = false;
31+
pub const DUMP_LOGS: bool = cfg!(debug_assertions);
32+
33+
lazy_static! {
34+
pub static ref LOG_ENV: bool = env::var("RAYON_RS_LOG").is_ok();
35+
}
2736

2837
macro_rules! log {
2938
($event:expr) => {
30-
if ::log::DUMP_LOGS { println!("{:?}", $event); }
39+
if ::log::DUMP_LOGS { if *::log::LOG_ENV { println!("{:?}", $event); } }
3140
}
3241
}
3342

0 commit comments

Comments
 (0)