pub struct JsonLogger { /* private fields */ }Expand description
This logger is a implementation for log::Log trait.
Implementations§
Source§impl JsonLogger
impl JsonLogger
Sourcepub fn init(output: LoggerOutput, filter: LogLevelFilter)
pub fn init(output: LoggerOutput, filter: LogLevelFilter)
#[macro_use]
extern crate log;
#[macro_use]
extern crate s_structured_log;
extern crate serde_json;
use log::LogLevelFilter;
use s_structured_log::{JsonLogger, LoggerOutput};
fn main() {
JsonLogger::init(LoggerOutput::Stderr, LogLevelFilter::Info);
s_info!(json_object! {
"key" => "value"
});
}Examples found in repository?
examples/basic.rs (line 10)
9fn main() {
10 JsonLogger::init(LoggerOutput::Stdout, log::LogLevelFilter::Info);
11
12 s_trace!(json_object! {
13 "trace_key1" => 1,
14 "trace_key2" => "value2"
15 });
16 s_debug!(json_object! {
17 "debug_key1" => 1,
18 "debug_key2" => "value2"
19 });
20 s_info!(json_object! {
21 "info_key1" => 1,
22 "info_key2" => "value2"
23 });
24 s_warn!(json_object! {
25 "warn_key1" => 1,
26 "warn_key2" => "value2"
27 });
28 s_error!(json_object! {
29 "error_key1" => 1,
30 "error_key2" => "value2"
31 });
32
33 trace!("{:?}",
34 json_object! {
35 "trace_key1" => 1,
36 "trace_key2" => "value2"
37 });
38 error!("{}",
39 json_format! {
40 "error_key1" => 1,
41 "error_key2" => q("value2"),
42 "error_key3" => json_format![q("value3"),4]
43 });
44}More examples
examples/complicated_json.rs (line 10)
9fn main() {
10 JsonLogger::init(LoggerOutput::Stderr, log::LogLevelFilter::Info);
11
12 // use json_object!
13 s_info!(json_object! {
14 "Fruits" => json_object! {
15 "on_the_table" => json_object! {
16 "Apple" => 1,
17 "Orange" => "two",
18 "Grape" => 1.2
19 },
20 "in_the_basket" => ["Banana", "Strawberry"]
21 },
22 "Pets" => [
23 json_object! {
24 "name" => "Tama",
25 "kind" => "cat",
26 "age" => 3
27 },
28 json_object! {
29 "name" => "Pochi",
30 "kind" => "dog",
31 "age" => 5
32 }
33 ]
34 });
35
36 // use json_format! and target with `json:` prefix.
37 info!(target: &format!("json:{}", module_path!()),
38 "{}",
39 json_format! {
40 "Fruits" => json_format! {
41 "on_the_table" => json_format! {
42 "Apple" => 1,
43 "Orange" => q("two"),
44 "Grape" => 1.2
45 },
46 "in_the_basket" => json_format![q("Banana"), q("Strawberry")]
47 },
48 "Pets" => json_format![
49 json_format! {
50 "name" => q("Tama"),
51 "kind" => q("cat"),
52 "age" => 3
53 },
54 json_format! {
55 "name" => q("Pochi"),
56 "kind" => q("dog"),
57 "age" => 5
58 }
59 ]
60 });
61
62 // use json_format! and default target.
63 info!("{}",
64 json_format! {
65 "Fruits" => json_format! {
66 "on_the_table" => json_format! {
67 "Apple" => 1,
68 "Orange" => 2,
69 "Grape" => 1.2
70 },
71 "in_the_basket" => json_format![q("Banana"), q("Strawberry")]
72 },
73 "Pets" => json_format![
74 json_format! {
75 "name" => q("Tama"),
76 "kind" => q("cat")
77 },
78 json_format! {
79 "name" => q("Pochi"),
80 "kind" => q("dog")
81 }
82 ]
83 });
84}Trait Implementations§
Auto Trait Implementations§
impl Freeze for JsonLogger
impl RefUnwindSafe for JsonLogger
impl Send for JsonLogger
impl Sync for JsonLogger
impl Unpin for JsonLogger
impl UnwindSafe for JsonLogger
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more