1#[derive(Debug)]
3pub struct Parameter<'a> {
4 pub directive_env_key: &'a str,
6 pub display_source: bool,
7 pub display_target: bool,
8 pub color: bool,
9}
10
11impl Default for Parameter<'_> {
12 fn default() -> Self {
13 Self {
14 directive_env_key: "RUST_LOG",
15 display_source: true,
16 display_target: false,
17 color: true,
18 }
19 }
20}
21
22pub fn init() {
24 init_with(Parameter::default())
25}
26
27pub fn init_with(param: Parameter) {
29 use tracing_subscriber::{filter, fmt::time};
30
31
32 let Parameter {
33 directive_env_key,
34 display_source,
35 display_target,
36 color,
37 } = param;
38
39 if std::env::var(directive_env_key).is_err(){
40 std::env::set_var(directive_env_key, "info");
41 }
42
43 tracing_subscriber::fmt()
44 .with_timer(time::UtcTime::rfc_3339())
45 .with_ansi(color)
46 .with_file(display_source)
47 .with_line_number(display_source)
48 .with_target(display_target)
49 .with_env_filter(filter::EnvFilter::from_env(directive_env_key))
50 .init()
51}