q_debug/
lib.rs

1#[macro_use]
2extern crate lazy_static;
3
4#[macro_use]
5mod macros;
6
7pub mod fmt;
8pub mod logging;
9
10use chrono::Duration;
11pub use logging::LogLocation;
12pub use logging::Logger;
13use std::env;
14use std::fs;
15use std::sync::RwLock;
16
17lazy_static! {
18    pub static ref LOGGER: RwLock<Logger<fs::File>> = {
19        let qpath = env::temp_dir().join("q");
20        let file = fs::OpenOptions::new()
21            .write(true)
22            .create(true)
23            .append(true)
24            .open(&qpath)
25            .expect(&format!("Unable to open log file {:?}", qpath));
26        RwLock::new(Logger::new(file))
27    };
28}
29
30// TODO: Should this be in the API? Initially implemented to facilitate reducing
31// the header interval for integration tests but perhaps it's a useful feature?
32// If so, should this take `std::time::Duration` instead of `chrono::Duration`?
33// TODO: Similar function for setting `Logger.sink`?
34pub fn set_header_interval(d: Duration) {
35    LOGGER.write().unwrap().header_interval = d;
36}