1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use std::sync::Arc;
use arc_swap::{ArcSwap, Guard};
use lazy_static::lazy_static;
use slog::{o, Logger};
#[cfg(feature = "log")]
mod log_redirect;
#[cfg(feature = "log")]
pub use self::log_redirect::*;
fn discard_logger() -> Logger {
Logger::root(slog::Discard, o!())
}
lazy_static! {
static ref GLOBAL_LOGGER: ArcSwap<Logger> = ArcSwap::from(Arc::new(discard_logger()));
}
pub fn set_global(l: slog::Logger) {
GLOBAL_LOGGER.store(Arc::new(l));
}
pub fn get_global() -> Arc<Logger> {
GLOBAL_LOGGER.load_full()
}
pub fn borrow_global<'a>() -> Guard<'a, Arc<Logger>> {
GLOBAL_LOGGER.load()
}
pub fn clear_global() {
GLOBAL_LOGGER.store(Arc::new(discard_logger()));
}
#[macro_export]
macro_rules! crit( ($($args:tt)+) => {
::slog::slog_crit![**$crate::borrow_global(), $($args)+]
};);
#[macro_export]
macro_rules! error( ($($args:tt)+) => {
::slog::slog_error![**$crate::borrow_global(), $($args)+]
};);
#[macro_export]
macro_rules! warn( ($($args:tt)+) => {
::slog::slog_warn![**$crate::borrow_global(), $($args)+]
};);
#[macro_export]
macro_rules! info( ($($args:tt)+) => {
::slog::slog_info![**$crate::borrow_global(), $($args)+]
};);
#[macro_export]
macro_rules! debug( ($($args:tt)+) => {
::slog::slog_debug![**$crate::borrow_global(), $($args)+]
};);
#[macro_export]
macro_rules! trace( ($($args:tt)+) => {
::slog::slog_trace![**$crate::borrow_global(), $($args)+]
};);