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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
//! Logging scopes for slog-rs
//!
//! Logging scopes are convinience functionality for slog-rs that free user from manually passing
//! `Logger` objects around
//!
//! Note: Part of a `slog` logging philosophy is ability to freelly express logging contexts
//! acording to logical structure, rather than code structure. By using logging scopes logging
//! context is tied to code flow again, which is less expressive.
//!
//! ```
//!#[macro_use]
//! extern crate slog;
//! extern crate slog_scope;
//! extern crate slog_term;
//!
//! use slog::DrainExt;
//!
//! fn foo() {
//! info!(slog_scope::logger(), "foo");
//! }
//!
//! fn main() {
//! let log = slog::Logger::root(slog_term::streamer().stderr().build().fuse(), o!("version" => "0.5"));
//!
//! slog_scope::set_global_logger(log);
//! slog_scope::scope(slog_scope::logger().new(o!("scope" => "1")),
//! || foo()
//! );
//! }
extern crate slog;
extern crate lazy_static;
extern crate crossbeam;
use *;
use Arc;
use RefCell;
use ArcCell;
thread_local!
lazy_static!
/// Set global `Logger` that is returned by calls like `logger()` outside of any logging scope.
;
/// Access the `Logger` for the current logging scope
/// Execute code in a logging scope
///
/// Logging scopes allow using a `slog::Logger` without explicitly
/// passing it in the code.
///
/// At any time current active `Logger` for a given thread can be retrived
/// with `logger()` call.
///
/// Logging scopes can be nested and are panic safe.
///
/// `logger` is the `Logger` to use during the duration of `f`.
/// `with_current_logger` can be used to build it as a child of currently active
/// logger.
///
/// `f` is a code to be executed in the logging scope.
///
/// Note: Thread scopes are thread-local. Each newly spawned thread starts
/// with a global logger, as a current logger.